Skip to content

Commit

Permalink
Match fieldsets which contain the locator in legend child elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Firebaugh authored and John Firebaugh committed Oct 31, 2010
1 parent 80fbaf4 commit 21e7b3a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/xpath/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def link_or_button(locator)
end

def fieldset(locator)
descendant(:fieldset)[attr(:id).equals(locator) | descendant(:legend)[text.is(locator)]]
descendant(:fieldset)[attr(:id).equals(locator) | descendant(:legend)[string.n.is(locator)]]
end

def field(locator, options={})
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ <h1>Form</h1>
<p>
<fieldset id="some-fieldset-id" data="fieldset-id"></fieldset>
<fieldset data="fieldset-legend"><legend>Some Legend</legend></fieldset>
<fieldset data="fieldset-legend-span"><legend><span>Span Legend</span></legend></fieldset>
<fieldset data="fieldset-fuzzy"><legend>Long legend yo</legend></fieldset>
<fieldset data="fieldset-exact"><legend>Long legend</legend></fieldset>
</p>
9 changes: 5 additions & 4 deletions spec/html_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def all(*args)
describe '#fieldset' do
subject { :fieldset }

it("finds fieldsets by id") { get('some-fieldset-id').should == 'fieldset-id' }
it("finds fieldsets by legend") { get('Some Legend').should == 'fieldset-legend' }
it("accepts approximate legends") { get('Legend').should == 'fieldset-legend' }
it("prefers exact legend") { all('Long legend').should == ['fieldset-exact', 'fieldset-fuzzy'] }
it("finds fieldsets by id") { get('some-fieldset-id').should == 'fieldset-id' }
it("finds fieldsets by legend") { get('Some Legend').should == 'fieldset-legend' }
it("finds fieldsets by legend child tags") { get('Span Legend').should == 'fieldset-legend-span' }
it("accepts approximate legends") { get('Legend').should == 'fieldset-legend' }
it("prefers exact legend") { all('Long legend').should == ['fieldset-exact', 'fieldset-fuzzy'] }
end

describe '#field' do
Expand Down

0 comments on commit 21e7b3a

Please sign in to comment.