Window can't come to front fast enough to get button click

Ranorex Studio, Spy, Recorder, and Driver.
carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Window can't come to front fast enough to get button click

Post by carsonw » Thu Apr 26, 2012 8:12 pm

My test execution machine is having a problem clicking windows applications when there is a web browser in front of it.

Took a little while to figure out why, but I think I've got it now. Problem is, I don't know how to easily overcome this issue for all possible windows apps and their child windows.

What it looks like is happening is this:
  • Browser is open
  • Windows App is behind browser
  • Cursor is where windows app would be BUT browser is still in front (I think this is important)
  • Ranorex goes to click windows app
  • Ranorex brings windows app to front, to click the button
  • Ranorex excutes button click just before the app comes in front of the browser window so the click hits the browser instead of the app
  • No error is reported in clicking the button
  • The app never receives the button click method
  • The window that would have opened as a result of the button click does not - Ranorex throws an error saying the window is not found
This doesn't always happen, but it often happens. As an experiment, I had the browser take only half the screen, and put the windows app on the lower half so it was never behind the browser. In this case, every test iteration passed each time.
When the browser went back to full screen the test would sometimes:
  • fail every iteration
  • fail one or two iterations
The intermittent failures are what lead me to believe it's a timing issue. This issue never occurs on my dev machine, but it's faster than my test machine (both machines are Windows 7 64bit).

Any ideas on how I can work around this - resizing/moving the browser away from the windows app is not really a practical approach - if I could give a little more time for the application to come to the front, that would probably solve it, assuming the above is correct.

I've included a screenshot, in case it's useful, with some comments.
You do not have the required permissions to view the files attached to this post.

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Window can't come to front fast enough to get button click

Post by carsonw » Thu Apr 26, 2012 9:47 pm

I did some additional troubleshooting and here's what I found
  • Calling EnsureVisible() and then giving a Delay of two seconds before clicking the windows application button did not help.
  • I confirmed that the mouse is moving to the locations where the windows app's buttons are behind the browser window. The mouse pointer always moves to the correct location and the click always fires, but the browser is what ultimately gets clicked because it's the forward window...
  • Looking at the Windows toolbar (start bar?), I can see that the application's icon on the bar is never pressed, the browser's icon remain's pressed which suggests to me the application is NOT be selected however the application's icon is flashing, which I think means it TRIED to focus it but I'm not sure
  • Invoking the "Press" method (rather than Click), works 99% of the time. The window still never comes to the front, but the button is click "behind" the browser and the corresponding application form window pops up (in front of the browser). It's not my preference to use "Press" if possible, I would rather move there and "Click" like a user would if possible.
  • Both boxes have .NET 4.0 and the same version of Ranorex (the latest version) - the only difference is I have the windows SDK (through Visual Studio), and the test machine does not (so I can't, for example, compile on the test machine but it can run fine).

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Window can't come to front fast enough to get button click

Post by Support Team » Fri Apr 27, 2012 3:48 pm

Hi,

Do you have tried to call the Focus() method of the specific element before the click is performed?
Please also try to add a Validate- Exists action to the action table, right before the click action, this should normally work in your case.

Regards,
Markus
Ranorex Support Team

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Window can't come to front fast enough to get button click

Post by carsonw » Fri Apr 27, 2012 4:37 pm

I did try Focus on both the button and the window that contains the button and neither helped.

I can try the Validate Exists... hopefully that works. However, Ranorex definitely knows the application is there, it's moving the mouse and clicking the button location, it just fails to bring the app forward.

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Window can't come to front fast enough to get button click

Post by sdaly » Fri Apr 27, 2012 5:22 pm

Another thing to try is adding @visible='true' in your rxpath for the element...

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Window can't come to front fast enough to get button click

Post by artur_gadomski » Mon Apr 30, 2012 10:20 am

How about as a workaround click you app's icon on the task bar to bring it to front, wait a bit and then try to click a button.

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: Window can't come to front fast enough to get button click

Post by carsonw » Mon Apr 30, 2012 6:35 pm

artur_gadomski wrote:How about as a workaround click you app's icon on the task bar to bring it to front, wait a bit and then try to click a button.
I thought of that too (great minds think alike!), but unfortunately the way the app works is that some windows can have additional bars in the task bar and some may not - clicking the main app window may not necessarily bring forward the desired window - and the desired window may or may not have icon on the bar.

I can try sdlay's suggestion as well - it's just a pain because I'd (theoretically) have to do it with absolutely every item in the repository for that app and that's a LOT of items.

The frustrating thing is, this is not a problem on my dev machine - nor our pair station (basically another dev machine).

I'm going to do some more tests with windows calculator (just a simple app as opposed to ours) on the test box and see if that fails as well.

Also: thanks for the suggestions, always appreciate help from Ranorex support and the Ranorex community :)

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Window can't come to front fast enough to get button click

Post by artur_gadomski » Wed May 02, 2012 1:07 pm

Try running move to method first. This should bring the window to front and move the mouse to location of your button. Then a delay and then a click.
If window is not brought to front on move to method then it's probably not a timing issue.