From 06265cefd5e81c5f73c055c7275101a3a3a7481a Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Wed, 27 Jun 2018 12:53:58 -0700 Subject: [PATCH] Fix selenium issue with fieldset nested in disabled fieldset not being disabled --- lib/capybara/selector.rb | 2 + lib/capybara/selenium/node.rb | 3 +- .../selenium/nodes/marionette_node.rb | 4 +- lib/capybara/spec/session/node_spec.rb | 6 ++ lib/capybara/spec/views/form.erb | 56 +++++++++---------- 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/lib/capybara/selector.rb b/lib/capybara/selector.rb index aeb897a9..c7f39ca0 100644 --- a/lib/capybara/selector.rb +++ b/lib/capybara/selector.rb @@ -74,6 +74,8 @@ Capybara.add_selector(:fieldset) do xpath = xpath[XPath.child(:legend)[XPath.string.n.is(legend)]] if legend xpath end + + node_filter(:disabled, :boolean) { |node, value| !(value ^ node.disabled?) } end Capybara.add_selector(:link) do diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index 1a5810a8..cc17c87d 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -142,8 +142,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node def disabled? return true unless native.enabled? # WebDriver only defines `disabled?` for form controls but fieldset makes sense too - return boolean_attr(self[:disabled]) if tag_name == 'fieldset' - false + tag_name == 'fieldset' && find_xpath("ancestor-or-self::fieldset[@disabled]").any? end def content_editable? diff --git a/lib/capybara/selenium/nodes/marionette_node.rb b/lib/capybara/selenium/nodes/marionette_node.rb index 38d959f3..25da792d 100644 --- a/lib/capybara/selenium/nodes/marionette_node.rb +++ b/lib/capybara/selenium/nodes/marionette_node.rb @@ -13,8 +13,10 @@ class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node end def disabled? - return true if super + # Not sure exactly what version of FF fixed the below issue, but it is definitely fixed in 61+ + return super unless driver.browser.capabilities[:browser_version].to_f < 61.0 + return true if super # workaround for selenium-webdriver/geckodriver reporting elements as enabled when they are nested in disabling elements if %w[option optgroup].include? tag_name find_xpath("parent::*[self::optgroup or self::select]")[0].disabled? diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index 6a156013..5e91c3ff 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -208,6 +208,12 @@ Capybara::SpecHelper.spec "node" do expect(@session.find('//select[@id="form_disabled_select2"]/option').disabled?).to be true expect(@session.find('//select[@id="form_title"]/option[1]').disabled?).to be false end + + it "should be disabled for all elements that are CSS :disabled" do + @session.visit('/form') + # sanity check + expect(@session.all(:css, ':disabled')).to all(be_disabled) + end end describe "#visible?" do diff --git a/lib/capybara/spec/views/form.erb b/lib/capybara/spec/views/form.erb index 5fd42bc9..0c0717c1 100644 --- a/lib/capybara/spec/views/form.erb +++ b/lib/capybara/spec/views/form.erb @@ -370,7 +370,6 @@ New line after and before textarea tag

-

-

+

+ +
+ +
+ Disabled Child + + +
+ +
+ + Nested Disabled + + + + Another Legend + +
- -
-

- - -

-

- Disabled Child - - -
- -
- Nested Disabled - + Disabled? + - - Another Legend - - -

-

- -
-

+
-

+

+