I'm trying to select option 2, but first it is selecting 2 then changing to 1.
This is the HTML of the select list:
<select id="IDITForm@additionalVehicleDrivers|1@youngestDriverExperienceVO@id">
<option style="background-color: rgb(252, 218, 175);" value="-1">Select</option>
<option value="1">0</option>
<option value="2">1</option>
<option value="3">2</option>
<option value="4">3</option>
<option value="5">4</option>
<option value="1000000">5</option>
<option value="1000001">more than 5</option>
</select>
This is the Watir code for selecting 2:
b.select_list(:id,"IDITForm@additionalVehicleDrivers|1@youngestDriverExperienceVO@id").select "2"
The problem is that you are using Watir-Classic's
selectmethod with a parameter that matches both an option's text as well as another option's value.If you take a look at the code for the
Watir::SelectList#selectmethod:You can see that:
For your specific example, this means that
<option value="2">1</option>matches since itsvalueis "2"<option value="3">2</option>matches since itstextis "2"Given the way the method is written and how your select list is written, you cannot use the
selectmethod. While the best choice is to move to Watir (previously Watir-Webdriver), there are workarounds in Watir-Classic.Remove the ambiguity by specifically selecting an option based on only the
valueattribute:If you want to stick to selecting by text, directly locate/select the option element: