Role.Text

Class library usage, coding and language questions.
sahoko
Posts: 9
Joined: Tue Oct 09, 2007 5:07 pm

Role.Text

Post by sahoko » Tue Oct 09, 2007 5:27 pm

I'm unable to enter text to a text box. The spy tells me the element is the role type "Text". My code below finds the element, but its State is always "ReadOnly". I think that's why I can't enter text to this text box, but I don't know why it's flagged as "ReadOnly" to begin with...

// enter username
foreach (Control control in form.Controls)
{

Element objUserName = control.Element.FindChild(Role.Text, "User Name:");

// this conditional gets hit twice
// the text attached to the text box is also recognized as this obj
if (objUserName != null)
{
Console.WriteLine("trying to type the username");
Console.WriteLine(objUserName.State);


objUserName.Value = "System";

Application.Sleep(2000);
//break;
}
}

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Tue Oct 09, 2007 5:58 pm

Please try the following:

Code: Select all

Element textbox = control.Element.FindChild(Role.Text, "UserName");
Mouse.ClickElement(textbox);
Application.SendKeys("Name");
This will set the focus to the textbox and enter the text "Name".

Jenö
Ranorex Support Team

sahoko
Posts: 9
Joined: Tue Oct 09, 2007 5:07 pm

Post by sahoko » Tue Oct 09, 2007 6:04 pm

Thanks for your solution. It worked. :D