【问题标题】:clicking dropDownMenu item - selenium ruby单击 dropDownMenu 项 - selenium ruby
【发布时间】:2012-02-20 19:27:37
【问题描述】:

我正在尝试单击“复制地址”按钮,然后单击下拉项“运送到帐单”选项。我可以按 id 单击按钮,但我的下一行脚本会引发错误,这就是我所拥有的 -

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')

到目前为止,我已经尝试了所有这些,但没有运气......点击按钮后,我尝试使用 find_element 进入下拉菜单,然后点击选项“Billing to Shipping”

任何帮助....谢谢

【问题讨论】:

  • 如果这对你有用,请将我的答案标记为收集解决方案
  • 我尝试了你的答案,但它没有用,但我确信在我澄清我的问题后,你可能有不同的方式来回答它......感谢时间。

标签: ruby selenium drop-down-menu option


【解决方案1】:

我相信你问的问题和这个人一样……因为 selenium-webdriver 以同样的方式处理很多元素。

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')

【讨论】:

  • 谢谢你,我发现这个方法优于其他答案
【解决方案2】:

这是我发现的一个更好的选择:

#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' }

【讨论】:

  • 为什么你认为它更好?
【解决方案3】:

这应该为你做......

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

其中 value number 是与“Billing to Shipping”对应的选项的值

【讨论】:

  • 这是点击 id "copyAddress" 后 html 的样子 ------
猜你喜欢
  • 1970-01-01
  • 2021-10-13
  • 2019-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-22
  • 2022-11-18
  • 2019-03-30
相关资源
最近更新 更多