Missing GetFocus() method

Class library usage, coding and language questions.
Gryphyn
Posts: 15
Joined: Wed Dec 06, 2006 11:59 pm

Missing GetFocus() method

Post by Gryphyn » Tue Jun 26, 2007 11:03 pm

Ranorex 1.2
.Net 2.0

I've just upgraded to Ranorex 1.2
When I go to recompile I get an error for every instance of
"Control <control> = <Form>.GetFocus()"

Investigation shows that this method is missing from the latest release.
:cry:

Cheers
Gryphyn

webops
Site Admin
Site Admin
Posts: 349
Joined: Wed Jul 05, 2006 7:44 pm

Post by webops » Wed Jun 27, 2007 9:48 pm

Investigation shows that this method is missing from the latest release.
I tried the following code with the VS2005Application.exe and it worked for me:

Code: Select all

for (int i = 0; i < 60; i++)
{
    Control control = Form.GetFocus();
    Console.WriteLine("Control = {0}", control.GetType());
    Application.Sleep(1000);
}
GetFocus is a static method, please use Form.GetFocus() and not an instance object.

Jenö
Ranorex Team

Gryphyn
Posts: 15
Joined: Wed Dec 06, 2006 11:59 pm

Post by Gryphyn » Thu Jun 28, 2007 12:39 am


spot
Posts: 8
Joined: Fri Apr 30, 2010 10:16 pm

Missing GetFocus() method

Post by spot » Sat May 01, 2010 1:01 am

Hello,

I have a AUT main GUI and sometimes some MessageBoxes (from the AUT) which must be handled before the next step can be done on the AUT main GUI. So when I recognize the AUT has not the focus I want to get the Form (MessageBox) with the focus and click "OK" (for example).

Now my question: How can I get this form?

(Using Ranorex 2.2.3 - I can't find a GetFocus() method.)

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

Re: Missing GetFocus() method

Post by Support Team » Mon May 03, 2010 8:54 am

Hi!

I think what you are looking for is the following blog
http://www.ranorex.com/blog/handling-di ... up-windows
on our homepage. This blog handle unexpected Dialog and Pop Up windows and click for example the button "OK" when a window appears.
spot wrote:(Using Ranorex 2.2.3 - I can't find a GetFocus() method.)
In Ranorex 2.X every element/adapter has the HasFocus property instead.

Regards,
Peter
Ranorex Support Team

spot
Posts: 8
Joined: Fri Apr 30, 2010 10:16 pm

Re: Missing GetFocus() method

Post by spot » Mon May 03, 2010 12:21 pm

Thank you very much for the very interesting link.

Unfortunately I search for a solution which is a little bit different. I would like to know which Form (e. g. MessageBox) is the one with the focus and then I would like to get the name or title of this Box.

Then I can decide if it is the expected Form (MsgBox) at the right time, can do something (depending to the meaning of the Box), can close the Box an can do the next test step on the AUT.

The solution in the given link closes Boxes in a separate thread when ever they open, and the main test program does not know which one it was and can't do something with this additional information (the meaning of the box), because only the separate thread knows about its existence.
And when a real unexpected box appears (which title isn't known before) there are no way to get this Form/Box and click OK, or Alt+F4 just as a try to go on with the test (of course with WARN and Screenshot - but maybe with the chance that the test can be finished).

So, the question again please: Do you know any method to get the MessageBox/form/control/name of or something else of the object with the focus?

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

Re: Missing GetFocus() method

Post by Support Team » Mon May 03, 2010 12:59 pm

Hi!
spot wrote:So, the question again please: Do you know any method to get the MessageBox/form/control/name of or something else of the object with the focus?
You can try following code:
//Search for the active foreground window and checks if "active" state is true
Ranorex.Form myActiveForm = Host.Local.FindSingle("/form[@active='True']");
Regards,
Peter
Ranorex Support Team

spot
Posts: 8
Joined: Fri Apr 30, 2010 10:16 pm

Re: Missing GetFocus() method

Post by spot » Mon May 03, 2010 1:37 pm

Thank you!

This could be the thing I've searched for - I will try it (a first short test worked).

I don't know, but maybe this could be a additional information to the link http://www.ranorex.com/blog/handling-di ... up-windows you told me?

Regards