Find the foremost window

Ask general questions here.
User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Find the foremost window

Post by Aracknid » Mon Jul 11, 2011 9:07 pm

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

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Find the foremost window

Post by Ciege » Mon Jul 11, 2011 9:52 pm

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.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Find the foremost window

Post by Support Team » Mon Jul 11, 2011 10:16 pm

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
.
Image