Mandy
Mandy

Reputation: 475

Watir::Exception::NoValueFoundException: No option with :text, :label or :value in this select element

Watir Automation testing: I'm trying to select an option from a select box , but since the options in the select box are set dynamically I am not able to do it correctly.

Html looks like :

     <select id="abc">
     <option>Select</option>
     <option>First</option>
     <option>Second</option>
     <option>Third</option>
     </select>

The command I'm trying to use is as follows :

$browser.select_list(:id, "abc").select("Second").

Since the options are dynamically set , the above command will fail if <option>Second</option> does not exist in the HTML .

error :

Watir::Exception::NoValueFoundException: No option with :text, :label or :value in this select element

What's the best way to implement this?Is there any way of selection using indexes/order?

Upvotes: 1

Views: 661

Answers (2)

alp2012
alp2012

Reputation: 281

Try using just the select method and adding the text attribute as seen below:

browser.select(:id, 'abc').option(:text, 'Second').select

or just

browser.option(:text, 'Second').select

Let me know how these work out for you.

Upvotes: 0

Justin Ko
Justin Ko

Reputation: 46836

You can set the option by index if you access the option directly.

Try:

$browser.select_list(:id, "abc").option(:index, 2).select

Upvotes: 1

Related Questions