clicking dropDownMenu item - selenium ruby

I'm trying to click a button 'Copy Address' then dropdown item 'Shipping to Billing' option. I'm able to click button by id but my next line of script throws an error, here is what I have -

click_element(@driver, :id, 'copyAddress')
@driver.find_element(:class, 'dropDownMenu')

#select(@driver, :class, 'dropDownMenu', 'Billing to Shipping')
#@driver.find_element(:class, 'dropDownItemOver')
#select(@driver, :class, 'dropDownItem', 'Billing to Shipping')

I've tried all this so far and no luck....After clicking the button I'm trying to get into the dropdownMenu with find_element and then clicking the option 'Billing to Shipping'

any help....thanks


I believe you're asking the same question as this guy... as the selenium-webdriver treats a lot of elements the same way.

How do I set an option as selected using Selenium WebDriver (selenium 2.0) client in ruby

dropDownMenu = @driver.find_element(:class, 'dropDownMenu')
option =
option.select_by(:text, 'Billing to Shipping')
option.select_by(:value, 'Billing to Shipping')

this should do it for you...

@driver.find_element(:id, "copyAddress").find_element(:css,"option[value='1']").click

where value number is the value of the option corresponding to "Billing to Shipping"

Here's a better option that I found:

#Select the dropdown button 
dropdown_list = driver.find_element(:id, 'copyAddress')

#Get all the options from the dropdown
options = dropdown_list.find_elements(tag_name: 'option')

#Find the dropdown value by text
options.each { |option| if option.text == 'Shipping to Billing' }

Need Your Help

Turn a page's javascript variable changes into a feed

javascript rss is the only website I follow that has neither RSS nor Twitter capabilities. I've tried services like page2RSS, and I've exhausted every last method of following a