0

I'm really struggling to handle a dropdown and submit box via Selenium on ruby. I've got to this and tried a number of other options:

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

Response:

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

Source code for the page

Any thoughts on how I can select the option then submit via the submit button?

4

1 回答 1

0
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

于 2015-10-12T16:55:31.097 回答