Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

don't find disabled fields

  • Loading branch information...
commit a8f970d0fa362410dd8d155fc41e238142a1617d 1 parent 6873e16
Jonas Nicklas authored
Showing with 33 additions and 6 deletions.
  1. +4 −4 lib/xpath/html.rb
  2. +15 −2 spec/fixtures/form.html
  3. +14 −0 spec/html_spec.rb
8 lib/xpath/html.rb
View
@@ -21,9 +21,9 @@ def link(locator)
#
def button(locator)
locator = locator.to_s
- button = descendant(:input)[attr(:type).one_of('submit', 'reset', 'image', 'button')][attr(:id).equals(locator) | attr(:value).contains(locator) | attr(:title).contains(locator)]
- button += descendant(:button)[attr(:id).equals(locator) | attr(:value).contains(locator) | string.n.contains(locator) | attr(:title).contains(locator)]
- button += descendant(:input)[attr(:type).equals('image')][attr(:alt).contains(locator)]
+ button = descendant(:input)[~attr(:disabled)][attr(:type).one_of('submit', 'reset', 'image', 'button')][attr(:id).equals(locator) | attr(:value).contains(locator) | attr(:title).contains(locator)]
+ button += descendant(:button)[~attr(:disabled)][attr(:id).equals(locator) | attr(:value).contains(locator) | string.n.contains(locator) | attr(:title).contains(locator)]
+ button += descendant(:input)[~attr(:disabled)][attr(:type).equals('image')][attr(:alt).contains(locator)]
end
@@ -167,7 +167,7 @@ def definition_description(locator)
protected
def locate_field(xpath, locator)
- locate_field = xpath[attr(:id).equals(locator) | attr(:name).equals(locator) | attr(:placeholder).equals(locator) | attr(:id).equals(anywhere(:label)[string.n.contains(locator)].attr(:for))]
+ locate_field = xpath[~attr(:disabled)][attr(:id).equals(locator) | attr(:name).equals(locator) | attr(:placeholder).equals(locator) | attr(:id).equals(anywhere(:label)[string.n.contains(locator)].attr(:for))]
locate_field += descendant(:label)[string.n.contains(locator)].descendant(xpath)
end
end
17 spec/fixtures/form.html
View
@@ -28,7 +28,7 @@
<input type="submit" title="My submit title" value="submit-with-title" data="title-submit">
<input type="submit" title="Exact submit title" value="exact title submit" data="exact-title-submit">
<input type="submit" title="Not Exact submit title" value="exact title submit" data="not-exact-title-submit">
-
+
<input type="reset" id="reset-with-id" data="id-reset" value="Has ID"/>
<input type="reset" value="reset-with-value" data="value-reset"/>
<input type="reset" value="not exact value reset" data="not-exact-value-reset"/>
@@ -36,7 +36,7 @@
<input type="reset" title="My reset title" value="reset-with-title" data="title-reset">
<input type="reset" title="Exact reset title" value="exact title reset" data="exact-title-reset">
<input type="reset" title="Not Exact reset title" value="exact title reset" data="not-exact-title-reset">
-
+
<input type="button" id="button-with-id" data="id-button" value="Has ID"/>
<input type="button" value="button-with-value" data="value-button"/>
<input type="button" value="not exact value button" data="not-exact-value-button"/>
@@ -77,6 +77,8 @@
<input type="schmoo" value="schmoo button" data="schmoo"/>
<label for="text-with-id">Label text <input type="text" id="text-with-id" data="id-text" value="monkey"/></label>
<label for="problem-text-with-id">Label text's got an apostrophe <input type="text" id="problem-text-with-id" data="id-problem-text" value="monkey"/></label>
+
+ <input disabled type="submit" id="disabled-submit" data="submit-disabled" value=""/>
</p>
<p>
@@ -185,4 +187,15 @@
<label>Input hidden with parent label<input type="hidden" data="input-hidden-with-parent-label-data"/></label>
<label>Input checkbox with parent label<input type="checkbox" data="input-checkbox-with-parent-label-data"/></label>
<label>Input radio with parent label<input type="radio" data="input-radio-with-parent-label-data"/></label>
+
+ <h4>Disabled</h4>
+ <input disabled id="input-disabled" value="correct-value" data="input-data"/>
+ <input disabled type="text" id="input-text-disabled" data="input-text-data"/>
+ <input disabled type="file" id="input-file-disabled" data="input-file-data"/>
+ <input disabled type="password" id="input-password-disabled" data="input-password-data"/>
+ <input disabled type="custom" id="input-custom-disabled" data="input-custom-data"/>
+ <textarea disabled id="textarea-with-id-data-disabled">Correct value</textarea>
+ <select disabled id="select-with-id-data-disabled"></select>
+ <input disabled type="checkbox" id="input-checkbox-disabled" data="input-checkbox-data"/>
+ <input disabled type="radio" id="input-radio-disabled" data="input-radio-data"/>
</p>
14 spec/html_spec.rb
View
@@ -84,6 +84,7 @@ def all(*args)
it("does not find the button") { get('schmoo button').should be_nil }
end
+ it("") { get('disabled-submit').should be_nil }
it("casts to string") { get(:'tag-with-tex').should == 'text-btag' }
end
@@ -158,6 +159,15 @@ def all(*args)
it("does not find hidden fields") { get('Input hidden with parent label').should be_nil }
end
+ context "is diabled" do
+ it("does not find inputs with no type") { get('input-disabled').should be_nil }
+ it("does not find inputs with text type") { get('input-text-disabled').should be_nil }
+ it("does not find inputs with password type") { get('input-password-disabled').should be_nil }
+ it("does not find inputs with custom type") { get('input-custom-disabled').should be_nil }
+ it("does not find textareas") { get('textarea-disabled').should be_nil }
+ it("does not find select boxes") { get('select-disabled').should be_nil }
+ end
+
it("casts to string") { get(:'select-with-id').should == 'select-with-id-data' }
end
@@ -176,6 +186,7 @@ def all(*args)
it("finds selects by name") { get('select-with-name').should == 'select-with-name-data' }
it("finds selects by label") { get('Select with label').should == 'select-with-label-data' }
it("finds selects by parent label") { get('Select with parent label').should == 'select-with-parent-label-data' }
+ it("does not find disabled selects") { get('select-disabled').should be_nil }
it("casts to string") { get(:'Select with parent label').should == 'select-with-parent-label-data' }
end
@@ -185,6 +196,7 @@ def all(*args)
it("finds checkboxes by name") { get('input-checkbox-with-name').should == 'input-checkbox-with-name-data' }
it("finds checkboxes by label") { get('Input checkbox with label').should == 'input-checkbox-with-label-data' }
it("finds checkboxes by parent label") { get('Input checkbox with parent label').should == 'input-checkbox-with-parent-label-data' }
+ it("does not find disabled") { get('input-checkbox-disabled').should be_nil }
it("casts to string") { get(:'Input checkbox with parent label').should == 'input-checkbox-with-parent-label-data' }
end
@@ -194,6 +206,7 @@ def all(*args)
it("finds radio buttons by name") { get('input-radio-with-name').should == 'input-radio-with-name-data' }
it("finds radio buttons by label") { get('Input radio with label').should == 'input-radio-with-label-data' }
it("finds radio buttons by parent label") { get('Input radio with parent label').should == 'input-radio-with-parent-label-data' }
+ it("does not find disabled") { get('input-radio-disabled').should be_nil }
it("casts to string") { get(:'Input radio with parent label').should == 'input-radio-with-parent-label-data' }
end
@@ -203,6 +216,7 @@ def all(*args)
it("finds file fields by name") { get('input-file-with-name').should == 'input-file-with-name-data' }
it("finds file fields by label") { get('Input file with label').should == 'input-file-with-label-data' }
it("finds file fields by parent label") { get('Input file with parent label').should == 'input-file-with-parent-label-data' }
+ it("does not find disabled") { get('input-file-disabled').should be_nil }
it("casts to string") { get(:'Input file with parent label').should == 'input-file-with-parent-label-data' }
end

1 comment on commit a8f970d

Darkvater

Could you elaborate why this change was made?
I would still be able to find a select box, input field, etc. even if it is disabled and asserting its value by using find_field on Capybara.

Please sign in to comment.
Something went wrong with that request. Please try again.