Read/get and set value of a form control?

Ask general questions here.
daluu
Posts: 26
Joined: Tue Jun 12, 2007 9:03 pm

Read/get and set value of a form control?

Post by daluu » Sat Jun 16, 2007 3:00 am

I briefly looked over the documentation for .NET and the sample for SharpDevelop.

I see that you can find form controls by name, etc. But can you read or get the default value or the list of values in a form control like a textbox, listbox, etc.?

And can you set the value of a form control like set a listbox to one of its prefined values in list (after reading the list of values) instead of sending up/down arrow keystrokes to select it in a manual GUI-wise fashion.

It would be nice if there are such features. If they exist already, can someone provide examples? Thanks.

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

Post by webops » Sun Jun 17, 2007 7:15 pm

1. Control classes

You can use the functions of the ListBox or TreeViw class for automating the standard controls.
See the RanorexVS2005Sample2 sample for more details.

You can read and select all items in a ListBox as follows:

Code: Select all

itemCount = listBox.ItemCount;
for (int i=0; i < itemCount;i++)
{
	text = listBox.GetItemText(i);
	Console.WriteLine("  Item[{0}]={1}",i,text);
	listBox.SelectedText = text;
}
2. Element class

The Ranorex element approach supports a general way to access every kind of control and control elements. It should also work with custom controls.

The following code reads all items from a listbox:
(This code works in V1.2.0-Beta2 or above)

Code: Select all

Element[] listItems = listView.Element.FindChildren(Role.ListItem, null, null, SearchMatchMode.MatchExact);
foreach (Element listItem in listItems)
{
    Console.WriteLine("Item={0})", listItem.Name);
}
The following code reads all items from a listbox beginning with "List":

Code: Select all

Element[] listItems1 = listView.Element.FindChildren(Role.ListItem, 
                            "List", null, SearchMatchMode.MatchFromStart);
foreach (Element listItem in listItems1)
{
    Console.WriteLine("Item={0})", listItem.Name);
}
See the RanorexVS2005Sample3 sample for more details.

Jenö
Ranorex Team

daluu
Posts: 26
Joined: Tue Jun 12, 2007 9:03 pm

Post by daluu » Mon Jun 18, 2007 6:40 pm

Thanks, I'll look into the documentation you specified.