mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Added support for labels without 'for' Closes #18
This commit is contained in:
parent
34e064fa4c
commit
ce914ed48e
3 changed files with 13 additions and 0 deletions
|
@ -105,6 +105,7 @@ module Capybara
|
||||||
def add_field(locator, field)
|
def add_field(locator, field)
|
||||||
xpath = append("#{field}[@id=#{s(locator)}]")
|
xpath = append("#{field}[@id=#{s(locator)}]")
|
||||||
xpath = xpath.append("#{field}[@id=//label[contains(.,#{s(locator)})]/@for]")
|
xpath = xpath.append("#{field}[@id=//label[contains(.,#{s(locator)})]/@for]")
|
||||||
|
xpath = xpath.append("//label[contains(.,#{s(locator)})]#{field}")
|
||||||
xpath.prepend("#{field}[@id=//label[text()=#{s(locator)}]/@for]")
|
xpath.prepend("#{field}[@id=//label[text()=#{s(locator)}]/@for]")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,12 @@ shared_examples_for "session" do
|
||||||
@session.click_button('awesome')
|
@session.click_button('awesome')
|
||||||
extract_results(@session)['first_name'].should == 'Harry'
|
extract_results(@session)['first_name'].should == 'Harry'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should fill in a text field by label without for" do
|
||||||
|
@session.fill_in('Street', :with => 'Avenue Q')
|
||||||
|
@session.click_button('awesome')
|
||||||
|
extract_results(@session)['street'].should == 'Avenue Q'
|
||||||
|
end
|
||||||
|
|
||||||
it "should favour exact label matches over partial matches" do
|
it "should favour exact label matches over partial matches" do
|
||||||
@session.fill_in('Name', :with => 'Harry Jones')
|
@session.fill_in('Name', :with => 'Harry Jones')
|
||||||
|
|
|
@ -17,6 +17,12 @@
|
||||||
<label for="form_name">Name</label>
|
<label for="form_name">Name</label>
|
||||||
<input type="text" name="form[name]" value="John Smith" id="form_name"/>
|
<input type="text" name="form[name]" value="John Smith" id="form_name"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label>Street<br/>
|
||||||
|
<input type="text" name="form[street]" value="Sesame street 66"/>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="form_phone">Phone</label>
|
<label for="form_phone">Phone</label>
|
||||||
|
|
Loading…
Reference in a new issue