Ranorex

Read/get and set value of a form control?

 
Post new topic   Reply to topic    Ranorex Forum Index -> General Questions
View previous topic :: View next topic  
Author Message
daluu



Joined: 12 Jun 2007
Posts: 10

PostPosted: Sat Jun 16, 2007 4:00 am    Post subject: Read/get and set value of a form control?
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.
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Sun Jun 17, 2007 8:15 pm    Post subject:
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: click into code to enlarge
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: click into code to enlarge
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: click into code to enlarge
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
Back to top
View user's profile Send private message Visit poster's website
daluu



Joined: 12 Jun 2007
Posts: 10

PostPosted: Mon Jun 18, 2007 7:40 pm    Post subject:
Thanks, I'll look into the documentation you specified.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> General Questions All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum