# How can I click on a button that is visible sometimes

**URL:** <https://forum.robotframework.org/t/how-can-i-click-on-a-button-that-is-visible-sometimes/6816>\
**Category:** Browser\
**Created:** [9 February 2024 17:44 UTC](https://forum.robotframework.org/t/how-can-i-click-on-a-button-that-is-visible-sometimes/6816 "2024-02-09T17:44:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PedroAugusto](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@PedroAugusto](https://forum.robotframework.org/u/PedroAugusto)\
**Post date:** [9 February 2024 17:44 UTC](https://forum.robotframework.org/t/how-can-i-click-on-a-button-that-is-visible-sometimes/6816/1 "2024-02-09T17:44:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [10 February 2024 05:02 UTC](https://forum.robotframework.org/t/how-can-i-click-on-a-button-that-is-visible-sometimes/6816/2 "2024-02-10T05:02:23Z")

</div>

Hi Pedro,

Perhaps what you are looking for is [Get Element States](https://marketsquare.github.io/robotframework-browser/Browser.html#Get%20Element%20States) combined with the `ElementState ` visible? This is the equivilent of SeleniumLibrary’s [Element Should Be Visible](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Element%20Should%20Be%20Visible)

Hope that helps,

Dave.

 ![Screenshot 2024-02-10 at 6.58.54 am](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/9/98abd4b5453b5a78f92a373336de1bdcecf3c085.png)

---

<div class="post-metadata">

**Author:** ![alex\_read](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/alex_read/32/3463_2.png) [@alex\_read](https://forum.robotframework.org/u/alex_read)\
**Post date:** [12 February 2024 07:17 UTC](https://forum.robotframework.org/t/how-can-i-click-on-a-button-that-is-visible-sometimes/6816/3 "2024-02-12T07:17:45Z")

</div>

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#Get%20Elements)
- [https://marketsquare.github.io/robotframework-browser/Browser.html#Finding%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’))]

---

<div class="post-metadata">

**Author:** ![PedroAugusto](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@PedroAugusto](https://forum.robotframework.org/u/PedroAugusto)\
**Post date:** [12 February 2024 12:37 UTC](https://forum.robotframework.org/t/how-can-i-click-on-a-button-that-is-visible-sometimes/6816/4 "2024-02-12T12:37:58Z")

</div>

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

```

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/5/56a8b4aa82ecec59c4e3fdee80155508b4545d97.png)

I appreciate and thank you guys for the solution!
