How do you select an OptionTag from within a SelectTag : General Questions

How do you select an OptionTag from within a SelectTag

Ask general questions here.

How do you select an OptionTag from within a SelectTag

Postby Ciege » Wed Mar 11, 2009 1: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
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Postby Support Team » Wed Mar 11, 2009 11: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
Support Team
Site Admin
 
Posts: 4844
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Postby Ciege » Wed Mar 11, 2009 5: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!
User avatar
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Postby cnimnicht » Wed Mar 11, 2009 11: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
cnimnicht
 
Posts: 5
Joined: Fri Jan 30, 2009 1:46 am

Postby Ciege » Wed Mar 11, 2009 11: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
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

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

Postby Nicklas » Mon Sep 26, 2011 4: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?
Nicklas
 
Posts: 15
Joined: Mon Sep 26, 2011 3:53 pm

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

Postby Ciege » Mon Sep 26, 2011 4: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
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

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

Postby Nicklas » Tue Sep 27, 2011 9: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
Spy of our selectbox
Container.JPG (68.5 KiB) Viewed 72 times
Nicklas
 
Posts: 15
Joined: Mon Sep 26, 2011 3:53 pm

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

Postby Support Team » Tue Sep 27, 2011 12:53 pm

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
Support Team
Site Admin
 
Posts: 4844
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

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

Postby Aracknid » Tue Sep 27, 2011 4: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
User avatar
Aracknid
 
Posts: 126
Joined: Tue Aug 10, 2010 4:23 pm
Location: Toronto, Ontario, Canada


Return to General Questions

Who is online

Users browsing this forum: No registered users and 0 guests