Wait For Elements State usage

I am having an issue with this method:
Wait For Elements State xpath=... state=stable timeout=10s

I want to be able to click on a button when the button is available and clickable. I even tried to put Wait For Load State state=load timeout=10s but the Click fails to trigger the button.

I know that the Browser Library can be fast but even with the Waits I can’t seem to get the right time to trigger the Click. If I put a Sleep 2s before the Click, all works well but I’d like to avoid putting Sleep.
Can someone please help me out or point me to the right direction?

@AvéCésar What kind of error are you getting?

1 Like

I am getting an error from the next keyword but I am sure the culprit is the Wait For Elements State which doesn’t wait for the web element (the button) to be visible, defocused, attached… I tried everything.
Even if I set it to timeout=60s, it does not make a difference. The xpath is correct, I debugged it using Get Element.

@AvéCésar I’m guessing that the problem is not the state of the button. But that some process is not completed, that should be completed before clicking on the button. Hence the delay of 2 seconds works, but waiting for a state of the button does not.

2 Likes

@AvéCésar Maybe you can use: Wait For Load State   networkidle   timeout=10 seconds

2 Likes

@falcon030 I am a total noob in the web dev world and I can’t seem to figure out what process is blocking the click of the button.
I tried Wait For Load State networkidle timeout=10 seconds with the same outcome. For now, the only hack workaround I found without using Sleep is Click With Options ${button_locator} clickCount=2 delay=0.5s

@AvéCésar That’s a creative solution :grinning:. Is there maybe some kind of loading indicator that there is a process going on like a spinner or something else? File:Loading icon.gif - Wikimedia Commons

@falcon030 No there isn’t any loading indicator. That’s why I wanted to use Wait For Elements State just to be 100% sure.
I tried to debug the button using Get Element States before and after Sleep 2s and the only ElementState that changes was defocused. But even with a Wait For Elements State xpath=... state=defocused timeout=10s it didn’t work. I knew I was throwing stones at a brick wall at that point that’s why I posted on this forum.

Sounds like a nice application that you are trying to test automate :grinning:.
And if you try this:
Wait For Elements State xpath=... state=defocused timeout=10s
Wait For Elements State xpath=... state=focused timeout=10s
Wait For Elements State xpath=... state=defocused timeout=10s

1 Like

I figured out the problem.
The problem wasn’t with the state of the button itself.
The web app triggers a backend api call on that page so I need to add
Wait For Response **/api/... timeout=30s
before even trying to Click ${button}.
Otherwise, the button doesn’t do anything. That’s why the Sleep 2s worked because the api response was succeeding after 2s.
Thank you @falcon030 for your help.

@AvéCésar It’s great to hear that you found a solution.