This question is regarding the select_list in watir.
We have a web application which is behaving strangely.
There is a four page form that allows users to register on the website and in one of the pages of the form there is a select_list where the user has to select one of the list of values.
The list of values are the list of cities.
the HTML code of the select list is like this
<select id="roleDetailsForm:city" name="roleDetailsForm:city">
<option value="">---Select---</option>
<option value="ABG">ABINGDON, QL</option>
</select>
The watir code I have written to select one of the list of values is
@browser.select_list(:name => "roleDetailsForm:city").set "ADELAIDE, SA"
The issue is
The developers logs says that select_list is sending the text instead of value to the sever, which is failing the request.
So, instead of ADL going as the value selected to the server, "ADELAIDE, SA" is going as the value selected.
However, this is happening only when running the script.
When a user manually selects the same text in the select_list and clicking on submit, it is sending "ADL" as value which is correct
Right now, the developer has been insisting that it is due to the script that the application is behaving strangely.
However, I am unable to figure why this is happening?
Eager to know if anyone else has experienced such issues and if this is really due to the script.
In addition to the watir code above I also tried
@browser.select_list(:name => "roleDetailsForm:city").set (@browser.select_list(:name => "roleDetailsForm:city").options[10])
.set
when setting an input field to some arbitrary value (like with a text field) to pick an option from a select list, you want the.select
method instead. See anonygoose's answer below – Chuck van der Linden