1
votes

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])
2
use .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 belowChuck van der Linden

2 Answers

3
votes

Try using

@browser.select_list(:name => "roleDetailsForm:city").select("ADELAIDE, SA")

I think set is just an alias for select in the original Watir, but I'm not certain anymore.

It's worth a shot.

0
votes

You could try:

@browser.select_list(:name => "roleDetailsForm:city").select_value('ADL')

Is there perhaps a hidden field that gets populated when you select something from the select list (and the hidden field is what is being checked on the server? Maybe use Firebug or similar to check if there are any events being run when you manually select from the list.