From 04a9806167d2f35be0b7fc20aecdd8beb91b4bcc Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Wed, 27 Jun 2018 10:19:47 -0700 Subject: [PATCH] fieldset elements should correctly respond to `disabled?` --- lib/capybara/selenium/node.rb | 5 ++++- lib/capybara/spec/session/node_spec.rb | 5 +++++ lib/capybara/spec/views/form.erb | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index d22d8710..1a5810a8 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -140,7 +140,10 @@ class Capybara::Selenium::Node < Capybara::Driver::Node alias :checked? :selected? def disabled? - !native.enabled? + 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 end def content_editable? diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index 009e45a2..6a156013 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -177,6 +177,11 @@ Capybara::SpecHelper.spec "node" do expect(@session.find('//option', text: "A.2")).not_to be_disabled end + it "should see a disabled fieldset as disabled" do + @session.visit('/form') + expect(@session.find(:css, '#form_disabled_fieldset')).to be_disabled + end + context "in a disabled fieldset" do # https://html.spec.whatwg.org/#the-fieldset-element it "should see elements not in first legend as disabled" do diff --git a/lib/capybara/spec/views/form.erb b/lib/capybara/spec/views/form.erb index a55f07c9..5fd42bc9 100644 --- a/lib/capybara/spec/views/form.erb +++ b/lib/capybara/spec/views/form.erb @@ -386,7 +386,7 @@ New line after and before textarea tag

-

+
Disabled Child