Error in Form.GetFocus()

Bug reports.
arishahsan
Posts: 26
Joined: Thu Jan 18, 2007 12:04 pm

Error in Form.GetFocus()

Post by arishahsan » Mon Apr 16, 2007 6:58 am

I have used the following code

Form CyMsgForm = Application.FindFormTitle("MyFormText")
Control MsgMngrFocusedButton = CyMsgForm.GetFocus();
Mouse.ClickControl(MsgMngrFocusedButton);

The problem is that when I tried this the mouse doesn't click on
the button in spite of it it clicks beside the control.

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

Post by webops » Mon Apr 16, 2007 8:25 pm

Hi,

I can't reproduce this bug.

I think the GetFocus() method returns another control you want to click on.

Please check the focused control's title:

Code: Select all

Form form = Application.FindFormTitle("MyFormText");
Control MsgMngrFocusedButton = Form.GetFocus();
Console.WriteLine(MsgMngrFocusedButton.Text);
Mouse.ClickControl(MsgMngrFocusedButton); 
Gabor
Ranorex Team

arishahsan
Posts: 26
Joined: Thu Jan 18, 2007 12:04 pm

I have tried ur idea and gives the name of same control

Post by arishahsan » Tue Apr 17, 2007 5:49 am

I have tried ur idea and it gives the name of the same control which I wanted to click.

You can reproduce it like this

Open Notepad and write something and try to close it without saving , so you will get a message box which is asking that do you want to save or not. Now run the following code.


Form MsgMng = Application.FindFormTitle("Notepad");
Control MsgYes = MsgMng.GetFocus();
Console.WriteLine(MsgYes.Text);
Mouse.MoveToControl(MsgYes);
Mouse.ClickControl(MsgYes);

The point to be noted is that the control doesn't have control name and this is applicable to any .net application, bcoz Message forms control name cannot be assigned by devlopers.

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

Post by webops » Wed Apr 18, 2007 9:45 pm

We cannot reproduce this bug.
If we do the same you described, the Form with the title "Notepad" will be activated and the mouse clicks the Yes button.
But we had to change your code a little bit:

Control MsgYes = Form.GetFocus();

Can you please try the following code and post the command line output in your replay.

Code: Select all

Form MsgMng = Application.FindFormTitle("Editor");
Control MsgYes = Form.GetFocus();
Console.WriteLine("Text={0} Class={1} Type={2}", 
    MsgYes.Text, MsgYes.ClassName, MsgYes.GetType());
Mouse.MoveToControl(MsgYes);
Mouse.ClickControl(MsgYes);
Which Ranorex and OS Version do you use?

Jenö
Ranorex Team

arishahsan
Posts: 26
Joined: Thu Jan 18, 2007 12:04 pm

I got this error in version 0.9.2

Post by arishahsan » Thu Apr 19, 2007 2:03 pm

It is working fine in version 1.1