Page 1 of 1

How do you select an OptionTag from within a SelectTag

Posted: Wed Mar 11, 2009 12:46 am
by Ciege
On my webdocument I find a ComboBox (SelectTag) item. From that SelectTag Item how do I select an Option below it?

I am using VS2008 with C#.

Code: Select all

DOMCombo = webDocumentName.FindSingle(".//select[@Id='" + ComboName + "']");
DOMCombo.Focus();
DOMCombo.??????
In this case there are a few OptionTags under this SelectTag, but I do not see a method for the SelectTag to click a specific Option by it's text value.

Thanks...

Posted: Wed Mar 11, 2009 10:55 am
by Support Team
The simplest way is to set it directly:

Code: Select all

SelectTag combo = ...
combo.TagValue = "text";
If there is some javascript wired to it, this might not work, though.
In this case I suggest using the the mouse:

Code: Select all

SelectTag combo = ...

// open the combo box            
combo.Click(Location.CenterRight);

// find the right item in the popup and click it
ListItem item = "/container[@caption='selectbox']/listitem[@text='green']";
item.Click();
This is a bit arcane so we will add some functionality in the SelectTag and OptionTag to simplify this. However, the RanorexRecorder generates code that is similar to the code above.

Michael
Ranorex Support Team

Posted: Wed Mar 11, 2009 4:19 pm
by Ciege
And again, thank you.

I was using the first method you described by setting the ComboBox directly, but it wasn't firing the onclick event.

So I changed to the item.click method you described below and that seems to work fine. I would like to see an actual .itemclick or .itemselect type of method implemented for the SelectTag in the future but for now this works.

Thanks!

Posted: Wed Mar 11, 2009 10:46 pm
by cnimnicht
Hi,

I've been trying to get this sample to work

SelectTag combo = ...

// open the combo box
combo.Click(Location.CenterRight);

// find the right item in the popup and click it
ListItem item = "/container[@caption='selectbox']/listitem[@text='green']";
item.Click();

I'm having issues with the line of code ListItem item = "/container[@caption='selectbox']/listitem[@text='green']"; , I figure that I am not using the right path. Any tips?

Thanks,
Chris Nimnicht

Posted: Wed Mar 11, 2009 10:51 pm
by Ciege
Does your list contain an item named "green"? If not, you need to change (or variableize) the word "green" to match what the item is in your combobox.

Code: Select all

ListItem item = "/container[@caption='selectbox']/listitem[@text='" + YourItemVariable + "']"; 

Re: How do you select an OptionTag from within a SelectTag

Posted: Mon Sep 26, 2011 3:27 pm
by Nicklas
Hope you dont mind me borrowing the thread. I managed to get Ranorex to select an option from the dropdown but when I try to select an option that's not visible at the moment it doesn't work.

We have a select where you input your age (18-99) and the age 35 is selected as default, so the ages 18-34 are "above" the preselected value of 35 and trying to get Ranorex to select one of thoose values just doesn't work. Any ideas?

Re: How do you select an OptionTag from within a SelectTag

Posted: Mon Sep 26, 2011 3:35 pm
by Ciege
If you open the list and view it with Spy does it show "18-34" as an available item from within the list?
If not, then it is drawn when needed and you will have to populate the list by scrolling through the entire list.
If it does, then you should be able to check on a property of where it lies in the list and scroll up or down depending on where it lives in the list.

Re: How do you select an OptionTag from within a SelectTag

Posted: Tue Sep 27, 2011 8:06 am
by Nicklas
Thank you for your reply. 18-34 does not show as available in Spy so I guess have to scroll to find the value I want?
Can you please show me an example how to scroll in code (or point me to where to find out). I tried to find the scrollbar in Spy but when I point at the scrollbar and/or the pageup button in scrollbar and track it the selectbox container gets selected. Dont see any scrollbars in there.
Container.JPG

Re: How do you select an OptionTag from within a SelectTag

Posted: Tue Sep 27, 2011 11:53 am
by Support Team
Hi,

Instead of scrolling to the item with the scrollbars you could use EnsureVisible or Focus to bring your items to the visible area.
http://www.ranorex.com/Documentation/Ra ... isible.htm
http://www.ranorex.com/Documentation/Ra ... _Focus.htm

Regards,
Peter
Ranorex Team

Re: How do you select an OptionTag from within a SelectTag

Posted: Tue Sep 27, 2011 3:15 pm
by Aracknid
Another thing you can try (if it works for your control) is to use the keyboard keys. I wrote my own custom function to select items from a combo box (it was for a silverlight combo mind you) because the focus and ensurevisible did not work for me with this control. So what I did was click the drop down, and when it was present, I would hit CTRL+PageUp to force it to scroll to the top and then as I walked through the list, I'd hit down (or you can make it faster if you hit page down if the control supports it) if my item was not visible.

Aracknid