How can I click on a button that is visible sometimes

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,



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:

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

I appreciate and thank you guys for the solution!