Waiting until the window is activated
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Waiting until the window is activated
I have following code that sets off a timer periodically and click "OK" a button. At the moment, I'm seeing two issues.
1) mouse moves on to the "OK" button (since there is no mouse move commands, it must be executing the mouse click), but the "OK" button does not get clicked. (Wait for the button object can see the "OK" button).
2) After missed button click, I see message saying "Waiting until the window is activated" and id doesnt go away. (Without the timer, "OK" button click works fine). It looks as if control doesnt get returned to the main for loop after handleRestartDeviceCautionForm() gets executed.
During the time handleRestartDeviceCautionForm() executes, I need rest of the code to pause, because this "Restart Device Form" blocks all the functionality in the application. This is being run on Win7 with Python 3.4.3. Can anyone show me how to over come this issue?
Below is the code:
#Main func cancel_future_calls = call_repeatedly(60, handleRestartDeviceCautionForm) for i in range(120): Delay(1000) cancel_future_calls() # stop future calls #Timer code from threading import Timer import threading from threading import Event, Thread def call_repeatedly(interval, func, *args): stopped = Event() def loop(): while not stopped.wait(interval): # the first call is in `interval` secs func(*args) Thread(target=loop).start() return stopped.set #Code that handles ok button def handleRestartDeviceCautionForm(): Tgence = ConfigTool() if Tgence.getzremindBtn().Exists: Tgence.getzremindBtn().ClickButton() Delay(100)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, I'm not at all experienced in Python so some of what I'm seeing may just be me. However, look at the following line of code:
if Tgence.getzremindBtn().Exists
I'm not sure what "getzremindBtn()" is... it appears to be a call to an object. If this is the case, and there's not some other processing going on, you are checking for the "exists" property on an object that, potentially, does not exist yet. This could cause some odd errors and problems. Check out the following topic and see if you can add one of those WaitNNN methods to your code in order to better handle this code.
https://support.smartbear.com/viewarticle/82625/?q=WaitNNN#WaitMethods
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much for responding.
In this case, it does find the object, every time. Then it seems like mouse click even gets executed to a certain degree. What I mean by that is, since the curser move into the correct position for the mouse click, I assume mouse click gets executed. However, "OK" button never gets pressed.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another possibility could be that there is a "flicker" in the object. It is found, it exists, and the click method appears to work, but the object may change state somewhere in the process where the click may execute but it may not actually be valid at that point. This is something I've rarely seen in my experience but it is, technically, possible.
Just as a diagnostic bit, have you tried putting a Delay call in the code before your call to click? Add maybe a second or two delay before the click to give the application a chance to "stabilize" before the click is excuted. What this might indicate, if it works, is that you need to do some additional checks other than "exists" to make sure that you can actually click the button. You might need to use a WaitProperty call on the button to make sure it's enabled.
Just a few things to try.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
