Page 1 of 1

Error in Form.GetFocus()

Posted: Mon Apr 16, 2007 6:58 am
by arishahsan
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.

Posted: Mon Apr 16, 2007 8:25 pm
by webops
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

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

Posted: Tue Apr 17, 2007 5:49 am
by arishahsan
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.

Posted: Wed Apr 18, 2007 9:45 pm
by webops
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

I got this error in version 0.9.2

Posted: Thu Apr 19, 2007 2:03 pm
by arishahsan
It is working fine in version 1.1