I need to click on a button, but it only appears under certain circumstances. Using the Selenium library, I could validate by storing the status using the keyword ‘Run Keyword and Return Status’ and using ‘IF’ to check if it was visible or not. However, now with the Browser library, I couldn’t achieve the same. Does anyone have any ideas on how I can do this?
Hi Pedro,
Perhaps what you are looking for is Get Element States combined with the ElementState
visible? This is the equivilent of SeleniumLibrary’s Element Should Be Visible
Hope that helps,
Dave.
3 Likes
You could use the Browser library Get Elements keyword & check for an empty collection… this will tell if 1 or more instances of the button are onscreen (or only 1 with strict mode). Please see:
- https://marketsquare.github.io/robotframework-browser/Browser.html#Get%20Elements
- https://marketsquare.github.io/robotframework-browser/Browser.html#Finding%20elements
With the selector, you could use an xpath with an AND operator in, something like…
//button[@name=‘soughtButton’ and not(contains(@style,‘display:none’))]
1 Like
Thank you @damies13 and @alex_read, I managed to find a solution based on what you guys sent, and it worked perfectly fine.
Here’s the code:
${visible_element}= Get Element States id=button then bool(value & visible)
IF ${visible_element}
Click button
END
I appreciate and thank you guys for the solution!
3 Likes