Automated testing with Watir (or WatiN or similar): Disambiguating Select Elements
Problem: I'm looking for a way to run a test that can disambiguate between selectors that have the same meaning in multiple places.
Example:
I am trying to select the third "Monday" from the selected control
ie.select_list( :id , 'choose-day' ).set( '-monday' );
where the select control has some sort of "outline" format in the control itself:
alice
-monday
-tuesday
bob
-monday
-tuesday
charlie
-monday
-tuesday
Given that the text is identical (and I don't know which parameter values ββare ahead of the time), is there a way to code the test in such a way that the one that is selected is selected under charlie on Monday?
source to share
In WatiN, you can use multiple attribute support to match an element (I thought something similar is also available in Watir).
Option = ie.SelectList ("select-day"). Options (Find.ByText ("- Monday") & Find.ByIndex (2))
(the index is zero, so 2 will give the third match (if any)).
NTN, Jeroen van Menen Lead dev WatiN
source to share
It looks like you can use element_by_xpath to find the parameter you want:
// select / option [text () = 'charlie'] / following :: option [text () = '- monday']
then you can check the value attribute of that parameter (not sure how to do it in Watir) and select it using:
ie.select_list( :id , 'choose-day' ).select_value( whatever_the_value_was );
source to share