views:

839

answers:

2

Problem: I am looking for a way to run a test that is able to disambiguate between select controls that have the same value in more than one place.

Example:

I am trying to choose the third "monday" from a select control

ie.select_list( :id , 'choose-day' ).set( '-monday' );

where the select control has a kind of "outline" format in the control itself:

alice
-monday
-tuesday
bob
-monday
-tuesday
charlie
-monday
-tuesday

Given that the text is identical (and I do not know what the option values are ahead of time) is there a way to code the test such that the monday under charlie is the one that gets selected?

+2  A: 

It looks like you could use element_by_xpath to find the option you want, with something like this:

//select/option[text()='charlie']/following::option[text()='-monday']

then you could check the value attribute of that option (not sure how to do this in Watir), and select it using:

ie.select_list( :id , 'choose-day' ).select_value( whatever_the_value_was );
Moss Collum
+2  A: 

Hi,

In WatiN you can make use of multiple attribute support to match an element (I thought something similar is also available in Watir).

Option option = ie.SelectList("choose-day").Options(Find.ByText("-monday") && Find.ByIndex(2))

(index is zero based so 2 will give the third match (if any)).

HTH, Jeroen van Menen Lead dev WatiN

Jeroen van Menen