Page 1 of 1

Element.Select(TakeFocus) not working

Posted: Fri May 11, 2007 5:45 pm
by grahama
I have a login dialog with edit boxes for a username and password. The element information from RanorexSpy is

Role:Client, Name:"User name:"
Role:Client, Name:"Password:"

My code is as follows:

Code: Select all

Element win = ... the login dialog ...
Element user = win.FindChild(Role.Client, "User name:");
Element pass = win.FindChild(Role.Client, "Password":);
user.Select(Selection.TakeFocus);
Application.SendKeys("bob");
Application.Sleep(100);
pass.Select(Selection.TakeFocus);
Application.SendKeys("secret");
But when the ranorex app runs, it enters both "bob" and "secret" into the username edit box. Nothing is entered into the password edit box.

I've printed the element location and size for user and pass and the values are correct.

How do I force an element to take the focus?

Thanks

Posted: Fri May 11, 2007 7:11 pm
by webops
Normally you use the control class in a login dialog:

Code: Select all

TextBox UserNameCtrl = form.FindTextBox("ctlText1");
TextBox PasswordCtrl = form.FindTextBox("ctlText2");

UserNameCtrl.Text = "text1";
PasswordCtrl.Text = "text2";
The Element.Select function works only within a control (ListView, TreeView,...), but doesn't activate an other control.
You can click into the element to activate it:

Code: Select all

Element user = UserNameCtrl.Element;
Element pass = PasswordCtrl.Element;

Mouse.ClickElement(user);
Application.SendKeys("bob");

Mouse.ClickElement(pass);
Application.SendKeys("secret"); 
Jenö
Ranorex Team