4

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

user1174303
  • 41
  • 1
  • 1
  • 2
  • if this works for u, please mark my answer as the collect solution – Amey Jan 29 '12 at 02:04
  • I tried your answer and it didn't work but I'm sure after I clarify my question you probably have a different way off answering it...appreciate the time. – user1174303 Jan 30 '12 at 23:40

3 Answers3

11

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 = Selenium::WebDriver::Support::Select.new(dropDownMenu)
option.select_by(:text, 'Billing to Shipping')
option.select_by(:value, 'Billing to Shipping')
Community
  • 1
  • 1
grumpasaurus
  • 732
  • 1
  • 6
  • 16
4

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| option.click if option.text == 'Shipping to Billing' }
djinc
  • 171
  • 3
  • 14
3

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"

Amey
  • 8,292
  • 9
  • 41
  • 60
  • Here is what the html looks like after clicking id "copyAddress" ------ – user1174303 Jan 30 '12 at 23:35
  • So after clicking copyAddress and when you hover over "Billing to Shipping" the class "dropDownItem" is actually "dropDownItemOver" and then you click the option but not sure how to click something with td nowrap .....? Sorry if my question was a bit off. – user1174303 Jan 30 '12 at 23:38