Find the foremost window : General Questions

Find the foremost window

Ask general questions here.

Find the foremost window

Postby Aracknid » Mon Jul 11, 2011 10: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
Aracknid
 
Posts: 126
Joined: Tue Aug 10, 2010 4:23 pm
Location: Toronto, Ontario, Canada

Re: Find the foremost window

Postby Ciege » Mon Jul 11, 2011 10: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
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Re: Find the foremost window

Postby Support Team » Mon Jul 11, 2011 11: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
User avatar
Support Team
Site Admin
 
Posts: 4842
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to General Questions

Who is online

Users browsing this forum: No registered users and 0 guests