" When a attribute is selected that is not present and no assertion operator is set, the keyword fails. If an assertion operator is set and the attribute is not present, the returned value is None . This can be used to assert check the presents or the absents of an attribute."
I have now tried to use the assertions in order to return the attribute and if one is not present to return None. However I have failed. Is it even possible?
The reason why I need this functionality is that in order to test some functionalities on the product Iām testing I need to fill in some mandatory fields. Some of these field need specific input and some general. The inputs are in different forms, text, numerical, checkboxās, radio buttons, calendar entries etc. None of these elements have one attribute that is present in all, so I need to get multiple attributes that I use to auto-fill these informationās. On Selenium it loos like this:
ā¦
${class}= Get Element Attribute ${i} class
${id}= Get Element Attribute ${i} id
${aria_label}= Get Element Attribute ${i} aria-label
${text}= Get Text ${i}
Run Keyword If āAction nameā in ā${placeholder}ā Input Text ${i} ${action} ${number}
ā¦ ELSE IF ātextā in ā${type}ā Input Text ${i} Some text inputed
Run Keyword If ānumberā in ā${type}ā Input Text ${i} 123
Run Keyword If ālistboxā in ā${role}ā Click Element ${i}
ā¦
So as you see, I use the attribute type to determine what the element is and how it should be handled and that is why I ask for a bunch of attributes, so I donāt need to assert whether or not any specific attribute is present, I just need the attribute or none.
Would Run Keyword And Ignore Error from the BuitIn Library help? you could use this with Get Element Attribute and first check if that passed if it did you can then check the attribute and perform your action.
Iām not sure which keyword documentation you were quoting there, as itās not the current version of Get Element Attribute. Iām guessing youāre using SeleniumLibrary? is it an old version?
I have actually tried āRun Keyword And Ignore Errorā but the funny thing about Browser is that it ignores that keyword and still fails.
I was quoting the Browser keyword documentation, Iām trying to migrate our Selenium tests to Browser and the code I used was for Selenium and I gave it as an example of what I did with Selenium. Now Iām trying to find out how to do it in Browser.
Now I could use āGet Attribute Namesā and then run āGet Attributeā if that attribute exists but something like this is not very sexy:
${list_of_attributes} Get Attribute Names ${element}
${type}= Set Variable None
${type} Run Keyword If ātypeā in ${list_of_attributes} Get Attribute ${element} type
I would not have guessed you were using Browser from your first message, just a tip, make these things clear in your initial post and youāll get better or quicker answers.
You could create your own keyword for āGet Element Attributeā for your browser tests, it could look like something like this:
*** keywords ***
Get Element Attribute
[Arguments] ${element} ${attr}
${list_of_attributes} Get Attribute Names ${element}
${value}= Set Variable None
${value}= Run Keyword If ${attr} in ${list_of_attributes} Get Attribute ${element}
${attr}
[Return] ${value}
Iām sorry, I just thought that since this is the sub section dedicated for Browser it would not be necessary to specifically state that I use Browser. Iāl be more clear in the future.
Anyways, thatās pretty much what I went with, I was just thinking there might be built-in function and I just missed it.
So you did, sorry I missed that as I picked it up from the latest list.
If itās not in the doc I treat it as doesnāt exist, Browser is not a drop in replacement for selenium, some things they take quite a different approach, if something was useful to me in Selenium library and there is no equivalent I just create a keyword for it, but I guess you could also raise a feature request with the Browser team, my usage of Browser has been pretty light.
Well the problem with this one was that the documentation was a bit vague.
It says that with no assertion it fails, but with some assertion it returns, so I figured that there might be some way for it to work in a way that it returns the attribute if it exists or none if it does not exist. Since it clearly capable of doing both of them in some situations.
But I suppose I might have to do some keywords of my own, I donāt think this is such a pressing issue to request a feature.