1
votes

I am trying to select an option from a select list using watir-webdriver.

watir-webdriver gem version : 0.6.4 Ruby 1.9.3 on mac osx lion

HTML of the select list:

<select id="cc.expiryMonth" name="cc.expiryMonth">
<option value="0">Month</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>

The code i used is

@browser.select_list(:name => "cc.expiryMonth").options[4].select

I am getting error

Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisibleError)
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/[email protected]/components/command_processor.js:7736:in `fxdriver.preconditions.visible'
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/[email protected]/components/command_processor.js:10437:in `DelayedCommand.prototype.checkPreconditions_'
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/[email protected]/components/command_processor.js:10456:in `DelayedCommand.prototype.executeInternal_/h'
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/[email protected]/components/command_processor.js:10461:in `DelayedCommand.prototype.executeInternal_'
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/[email protected]/components/command_processor.js:10401:in `DelayedCommand.prototype.execute/<'
  ./features/step_definitions/Wotif_FlightSearch_DOM_steps.rb:145:in `/^I enter all details on booking page$/'

Went through the watir-webdriver code in the gem library and exhausted all ways of selecting an option, all of them throw the same error.

@browser.select_list(:name => "cc.expiryMonth").focus

is successful, but selecting option throws element not visible error. Also tried send_keys unsuccessfully. Would appreciate any suggestions on how to handle this

UPDATE:

@browser.select_list(:name => "cc.expiryMonth").options[8].value

returns the value but

@browser.select_list(:name => "cc.expiryMonth").options[8].select

or

@browser.select_list(:name => "cc.expiryMonth").select @browser.select_list(:name => "cc.expiryMonth").options[8].value returns element not found error    
4
Is the select element always visible or do you have to perform an action to make the select element visible? The html sample and code you tried works by itself, so there is something else about the page that is causing the failure.Justin Ko
its at the bottom of the screen and the webdriver is scrolling down there and settings other select_lists there successfully.....rails4sandeep

4 Answers

0
votes

did you try this :

@browser.select_list(:name => "cc.expiryMonth").select '04'

or even

b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
s = b.select_list :name => 'cc.expiryMonth'
s.select '04'
s.selected_options

tell me what's up

0
votes

It could be a timing issue. Try this:

@browser.select_list(:name => "cc.expiryMonth").options[4].when_present.select

More information at http://watirwebdriver.com/waiting/

0
votes

I wonder if there's more than one select list with this name on the page, and Watir-webdriver is waiting for the first element, but the one that's visible is actually the second one.

Give this a try:

 p @browser.select_lists(:name => "cc.expiryMonth").count

Does it return higher than 1 in the command prompt / mac equivalent? If so you can use an index to select the one you want instead

@browser.select_list(:name => "cc.expiryMonth", :index => 1).select("04")
-2
votes

I was finally able to resolve the issue by following one of the other questions on stackoverflow where the suggestion is to use javascript to select the option in the select list.Nothing else worked.Happy that something worked finally