Page 1 of 1

Find the foremost window

Posted: Mon Jul 11, 2011 9:07 pm
by Aracknid
How do I find the window (form) that is in the foreground and has input focus without knowing what it is?

What I'm trying to do is take a screen shot of the window in the foreground when something unexpected has happend. So say I'm in IE and I get an unexpected IE dialog appear that has a javascript error and details... but it could also be any other dialog. And it could be from any other app, not IE.

I tried this but it didn't seem to work:
Dim MyForm as Ranorex.Form
Adapter.DefaultSearchTimeout = 30000
MyForm = "//form[@hasfocus='true']"
Thanks,

Aracknid

Re: Find the foremost window

Posted: Mon Jul 11, 2011 9:52 pm
by Ciege
Two things I can think of quickly.

1)You can just take a screenshot of the entire desktop:

Code: Select all

Report.Screenshot();
2) You can get an iList of Form objects that are children of the desktop, then iterate those objects checking the HasFocus property of each.

There is probably a better way to do it, but those are 2 quick ways that I could come up with.

Re: Find the foremost window

Posted: Mon Jul 11, 2011 10:16 pm
by Support Team
Aracknid wrote:How do I find the window (form) that is in the foreground and has input focus without knowing what it is?
The Form adapter has the Active property that is "true" for the currently active form. Consequently, the following RanoreXPath will get you the currently active form:

Code: Select all

/form[@active='True']
Regards,
Alex
Ranorex Team