Webdriver select lists in ruby

Selecting an option from a select list using the selenium-webdriver gem:

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'http://www.shino.de/parkcalc/'
Selenium::WebDriver::Support::Select.new(driver.find_element(:id => 'ParkingLot')).select_by :text, 'Economy Parking'

is much simpler in watir-webdriver

require 'watir-webdriver'
browser = Watir::Browser.new
browser.goto 'http://www.shino.de/parkcalc/'
browser.select_list(:id => 'ParkingLot').select 'Economy Parking'

That is all.

Author: Alister Scott

Alister is an Excellence Wrangler for Automattic.

5 thoughts on “Webdriver select lists in ruby”

  1. Perhaps we can write an extension method for IWebElement, to do the extra work of initialising select element

    Like

  2. Hi Alister,

    I was trying to implement your above example on a page that we are currently testing. The drop down list is accessed by clicking an arrow down button but we are still getting an ‘Element not visible’ message

    HTML:

    Select
    Medium
    Large
    XL
    XXL
    XXXL

    watir-webdriver code:
    browser.element(:css => “span.dropdown_btn”).click
    browser.select_list(:id => ‘redeumption’).select ‘Medium’

    the error message:
    Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisibleError)

    any help would be appreciated!

    Thanks.

    Like

Comments are closed.