在 Ruby 上使用 Selenium 处理带有提交按钮的下拉菜单

Handling a dropdown with submit button using Selenium on Ruby

我真的很难通过 ruby 上的 Selenium 处理下拉菜单和提交框。我已经做到了这一点并尝试了许多其他选择:

mySelect = browser.find_element(:id, "bulk_action")
option = mySelect.find_element(:css, "option[value='Accepted']")

回复:

[remote server] file:///var/folders/tt/pbz121011d1fvj5xmbyg78y00000gn/T/webdriver-profile20151012-46016-5sf82y/extensions/fxdriver@googlecode.com/components/driver-component.js:10659:in `FirefoxDriver.prototype.findElementInternal_': Unable to locate element: {"method":"id","selector":"bulk_action"} (Selenium::WebDriver::Error::NoSuchElementError)
from [remote server] file:///var/folders/tt/pbz121011d1fvj5xmbyg78y00000gn/T/webdriver-profile20151012-46016-5sf82y/extensions/fxdriver@googlecode.com/components/driver-component.js:10668:in `FirefoxDriver.prototype.findElement'
from [remote server] file:///var/folders/tt/pbz121011d1fvj5xmbyg78y00000gn/T/webdriver-profile20151012-46016-5sf82y/extensions/fxdriver@googlecode.com/components/command-processor.js:12534:in `DelayedCommand.prototype.executeInternal_/h'
from [remote server] file:///var/folders/tt/pbz121011d1fvj5xmbyg78y00000gn/T/webdriver-profile20151012-46016-5sf82y/extensions/fxdriver@googlecode.com/components/command-processor.js:12539:in `DelayedCommand.prototype.executeInternal_'
from [remote server] file:///var/folders/tt/pbz121011d1fvj5xmbyg78y00000gn/T/webdriver-profile20151012-46016-5sf82y/extensions/fxdriver@googlecode.com/components/command-processor.js:12481:in `DelayedCommand.prototype.execute/<'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/remote/response.rb:70:in `assert_ok'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/remote/http/common.rb:78:in `new'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/remote/http/common.rb:78:in `create_response'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/remote/http/default.rb:90:in `request'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/remote/bridge.rb:664:in `raw_execute'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/remote/bridge.rb:642:in `execute'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/remote/bridge.rb:611:in `find_element_by'
from /Users/chris/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.48.0/lib/selenium/webdriver/common/search_context.rb:61:in `find_element'
from mass_assign.rb:23:in `<main>'

关于如何select选项然后通过提交按钮提交的任何想法?

mass_accept = browser.find_element(id: 'bulk_action')
select_list = Selenium::WebDriver::Support::Select.new(mass_accept)
select_list.select_by(:text, 'Accept')
dropdown_button = browser.find_element(:class, "button--primary")
dropdown_button.click

非常感谢http://elementalselenium.com/tips/5-select-from-a-dropdown