How to wait for a button to be clickable

Best practices, code snippets for common functionality, examples, and guidelines.
fgmanfredini
Posts: 5
Joined: Wed Aug 04, 2021 10:26 pm

How to wait for a button to be clickable

Post by fgmanfredini » Wed Aug 04, 2021 10:55 pm

Hi, i need to wait for a button to be clickable before the action is executed. I have some popups that may or may not appear and all of them will be handled by popupWatchers, bu the problem is that as soon as all popupWatchers starts, the test immediately tries to click the button but fails because there is a modal popup that is showing and preventing the button from beeing clicked...

my test is like this:

1 - UserCode StartPopupWatcher Popup1
2 - UserCode StartPopupWatcher Popup2
3 - UserCode StartPopupWatcher Popup3
4 - UserCode StartPopupWatcher Popup4
5 - Mouse Click ButtonStart --< this action should be triggered only after the button becomes clickable (there is no popup showing anymore)
6 - Rest of the tests
7...


Any ideas on how to aproch this?

Thank You.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to wait for a button to be clickable

Post by odklizec » Fri Aug 06, 2021 7:03 am

Hi,

How exactly you identify the button in question is clickable? Is there an attribute? Could you please post a Ranorex snapshot (NOT screenshot) of the given button, ideally, create one for not-yet clickable button and clickable one. Thanks. Without, at very least, a Ranorex snapshot, there is not much anyone here can do or suggest.

As for the popupwatcher, the problem is, that it runs in a separate thread and main test threat does not wait for its actions. So if the clickability of a button depends on state of certain dialog/element, you will most probably have to use different solution than popupwatcher, which is supposed to be used for "randomly" appearing elements.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

fgmanfredini
Posts: 5
Joined: Wed Aug 04, 2021 10:26 pm

Re: How to wait for a button to be clickable

Post by fgmanfredini » Fri Aug 06, 2021 12:26 pm

odklizec wrote:
Fri Aug 06, 2021 7:03 am
Hi,

How exactly you identify the button in question is clickable? Is there an attribute? Could you please post a Ranorex snapshot (NOT screenshot) of the given button, ideally, create one for not-yet clickable button and clickable one. Thanks. Without, at very least, a Ranorex snapshot, there is not much anyone here can do or suggest.

As for the popupwatcher, the problem is, that it runs in a separate thread and main test threat does not wait for its actions. So if the clickability of a button depends on state of certain dialog/element, you will most probably have to use different solution than popupwatcher, which is supposed to be used for "randomly" appearing elements.
Thank you for your reply.. The button is always clickable, but the popup is blocking the application so the action tries to click the button and it do not respond because there is a modal popup on the screen.. I did not attach a snapshot because i think this is very simple and generic situation, a button to be clicked and a popup that shows randomnly but when it shows it blocks the application and the action can't click the button. What i need is a way to wait for all the popups to be gone before the action tries to click it.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to wait for a button to be clickable

Post by odklizec » Fri Aug 06, 2021 12:54 pm

Hi,

Well, I'm afraid, that in your particular case, popupwatcher is no way to go. As I mentioned in my previous post, popupwatcher runs in a separated thread and the main thread does not wait for its end. So you will have to cook up some sort of "CheckIfExistsandKillIt" method, which should be used before clicking the problematic button. If the popup is found, dismiss it and re-check the (not)existence of the popup. And only then continue with other stuff.

From your description, it seems to me that the popup does not appear entirely random? It appears (from time to time) at the same place, right? If the popup appears randomly, you will most probably have to use this method in every single recording. And even then, it may not be 100% reliable solution, if the popup could appear again, after you killed it once ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

fgmanfredini
Posts: 5
Joined: Wed Aug 04, 2021 10:26 pm

Re: How to wait for a button to be clickable

Post by fgmanfredini » Fri Aug 06, 2021 2:34 pm

odklizec wrote:
Fri Aug 06, 2021 12:54 pm
Hi,

Well, I'm afraid, that in your particular case, popupwatcher is no way to go. As I mentioned in my previous post, popupwatcher runs in a separated thread and the main thread does not wait for its end. So you will have to cook up some sort of "CheckIfExistsandKillIt" method, which should be used before clicking the problematic button. If the popup is found, dismiss it and re-check the (not)existence of the popup. And only then continue with other stuff.

From your description, it seems to me that the popup does not appear entirely random? It appears (from time to time) at the same place, right? If the popup appears randomly, you will most probably have to use this method in every single recording. And even then, it may not be 100% reliable solution, if the popup could appear again, after you killed it once ;)
Yes, the popup is not random, is only appears at the start of the aplication. the problem is that its not a single popup, its a series of popups that displays for the user once per day... so the next run for the same day they do not show and next day i run the app it comes again. Thats why i need a way to handle these popups if they appear and need to handle them all before the button is clicked. If think a way to do this is to try to click the button and check for the existence of the form is shows after clicking it.. and try to click it again if the form do not show... but i honestly think that i am not the only one that have this problem, popups is common and most of them usually block the screen , so i think there must be a better solution or at least a solution built into ranorex that does not rely on custom code to work around.... Maybe i am approaching this problem the worng way....

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: How to wait for a button to be clickable

Post by Stub » Mon Aug 09, 2021 9:27 am

I don't use PopupWatchers, I just wait for a short while to see if a potential form appears or not, and deal with it IFF it does. I've minimised the wait periods to a reliable and sufficienty short duration so they don't impact on the testing too much. I barely notice them, TBH, but it means our tests cope with scenarios where optional alerts and such may appear.

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: How to wait for a button to be clickable

Post by Fergal » Wed Aug 11, 2021 4:58 pm

fgmanfredini wrote:
Wed Aug 04, 2021 10:55 pm
as soon as all popupWatchers starts, the test immediately tries to click the button
Do you know why your Popup Watchers are not working? If they work, they should close the Popups before the test tries to click on the button.

You could consider adding steps to click on the buttons to close the popups, just before the action to click on the button you want to click on. If you make the timeouts for the popup repo items short and make the steps to click on those, enable continue on fail, your test should run successfully whether or not the popups appear.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to wait for a button to be clickable

Post by odklizec » Fri Aug 13, 2021 7:57 am

Fergal wrote:
Wed Aug 11, 2021 4:58 pm
If they work, they should close the Popups before the test tries to click on the button.
That's. I'm afraid, not entirely correct. The thing is, that popupwatchers run in a separate thread and does not interact with the main test thread. So it may happen (and it happens a lot) that the test does things BEFORE the popupwatcher is able to do its job. And what's worse, sometimes, the popupwatcher click messes-up with the mouse clicks in the main test thread. This is why I'm using popupwatchers pretty scarcely and only if I know they cannot break something else ;)

In my opinion, if the popups are predictable, they should handled directly in the test modules, using some conditions and loops here or there. Unfortunately, it's hard to suggest something more useful without access to the app under test.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: How to wait for a button to be clickable

Post by Fergal » Fri Aug 13, 2021 12:33 pm

odklizec wrote:
Fri Aug 13, 2021 7:57 am
... So it may happen (and it happens a lot) that the test does things BEFORE the popupwatcher is able to do its job. And what's worse, sometimes, the popupwatcher click messes-up with the mouse clicks in the main test thread...
Thanks for the clarification and additional info odklizec, it's not something I've experienced personally so it is good to know.

fgmanfredini
Posts: 5
Joined: Wed Aug 04, 2021 10:26 pm

Re: How to wait for a button to be clickable

Post by fgmanfredini » Tue Aug 17, 2021 6:35 pm

OK, maybe the popup watchers is not the solution. Could you give me an example of a loop that check for a popup existence and close it if it shows? As simple as this sounds, i could not find how to do this...

Thank You for your help!

odklizec wrote:
Fri Aug 13, 2021 7:57 am
Fergal wrote:
Wed Aug 11, 2021 4:58 pm
If they work, they should close the Popups before the test tries to click on the button.
That's. I'm afraid, not entirely correct. The thing is, that popupwatchers run in a separate thread and does not interact with the main test thread. So it may happen (and it happens a lot) that the test does things BEFORE the popupwatcher is able to do its job. And what's worse, sometimes, the popupwatcher click messes-up with the mouse clicks in the main test thread. This is why I'm using popupwatchers pretty scarcely and only if I know they cannot break something else ;)

In my opinion, if the popups are predictable, they should handled directly in the test modules, using some conditions and loops here or there. Unfortunately, it's hard to suggest something more useful without access to the app under test.

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: How to wait for a button to be clickable

Post by Stub » Wed Aug 18, 2021 8:52 am

I just write a MaybeHandlePopup style code module that calls Exists on an element of the popup with a short duration, typically a few seconds, though I tune that period to keep it as short as possible. If it returns true, then I deal with the popup. Otherwise I move on. No loop, just if (repo_item_info.Exists(some_duration)) some_other_repo_item.Click(); or something along those lines.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to wait for a button to be clickable

Post by odklizec » Wed Aug 18, 2021 10:19 am

fgmanfredini wrote:
Tue Aug 17, 2021 6:35 pm
OK, maybe the popup watchers is not the solution. Could you give me an example of a loop that check for a popup existence and close it if it shows? As simple as this sounds, i could not find how to do this...
Hi,
It would be helpful, if you post a Ranorex snapshot (NOT screenshot) of the app under test at a time when the popup is displayed and also when it's dismissed. And please post also the xpath of the elements you want to click (in popup) and after the popup is gone. Thanks.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration