How do you select an OptionTag from within a SelectTag

Ask general questions here.
User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

How do you select an OptionTag from within a SelectTag

Post by Ciege » Wed Mar 11, 2009 12:46 am

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...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Wed Mar 11, 2009 10:55 am

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Post by Ciege » Wed Mar 11, 2009 4:19 pm

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!

cnimnicht
Posts: 5
Joined: Fri Jan 30, 2009 12:46 am

Post by cnimnicht » Wed Mar 11, 2009 10:46 pm

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Post by Ciege » Wed Mar 11, 2009 10:51 pm

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 + "']"; 

User avatar
Nicklas
Posts: 20
Joined: Mon Sep 26, 2011 2:53 pm
Location: Sweden

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

Post by Nicklas » Mon Sep 26, 2011 3:27 pm

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?

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

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

Post by Ciege » Mon Sep 26, 2011 3:35 pm

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.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Nicklas
Posts: 20
Joined: Mon Sep 26, 2011 2:53 pm
Location: Sweden

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

Post by Nicklas » Tue Sep 27, 2011 8:06 am

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
You do not have the required permissions to view the files attached to this post.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

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

Post by Support Team » Tue Sep 27, 2011 11:53 am

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

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

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

Post by Aracknid » Tue Sep 27, 2011 3:15 pm

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