mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Added unselect to selenium driver
This commit is contained in:
parent
42a5eeb4f4
commit
291bb0fe72
1 changed files with 14 additions and 0 deletions
|
@ -35,6 +35,20 @@ class Capybara::Driver::Selenium < Capybara::Driver::Base
|
|||
raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
|
||||
end
|
||||
|
||||
def unselect(option)
|
||||
if node['multiple'] != 'multiple'
|
||||
raise Capybara::UnselectNotAllowed, "Cannot unselect option '#{option}' from single select box."
|
||||
end
|
||||
|
||||
begin
|
||||
option_node = node.find_element(:xpath, ".//option[text()='#{option}']") || node.find_element(:xpath, ".//option[contains(.,'#{option}')]")
|
||||
option_node.clear
|
||||
rescue
|
||||
options = node.find_elements(:xpath, "//option").map { |o| "'#{o.text}'" }.join(', ')
|
||||
raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
|
||||
end
|
||||
end
|
||||
|
||||
def click
|
||||
node.click
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue