Element.Select(TakeFocus) not working

Bug reports.
grahama
Posts: 8
Joined: Tue Apr 24, 2007 7:47 pm

Element.Select(TakeFocus) not working

Post by grahama » Fri May 11, 2007 5:45 pm

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

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

Post by webops » Fri May 11, 2007 7:11 pm

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