Ensure that exact label matches are favoured over partial matches.
This commit is contained in:
parent
3f9950e09d
commit
8f6fe3e553
|
@ -175,7 +175,7 @@ module Capybara
|
||||||
|
|
||||||
def find_field_by_label(locator, *kinds)
|
def find_field_by_label(locator, *kinds)
|
||||||
kinds.each do |kind|
|
kinds.each do |kind|
|
||||||
label = find("//label[contains(.,'#{locator}')]").first
|
label = find("//label[text()='#{locator}']").first || find("//label[contains(.,'#{locator}')]").first
|
||||||
if label
|
if label
|
||||||
element = find_field_by_id(label[:for], kind)
|
element = find_field_by_id(label[:for], kind)
|
||||||
return element if element
|
return element if element
|
||||||
|
|
|
@ -205,6 +205,12 @@ shared_examples_for "session" do
|
||||||
extract_results(@session)['first_name'].should == 'Harry'
|
extract_results(@session)['first_name'].should == 'Harry'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should favour exact label matches over partial matches" do
|
||||||
|
@session.fill_in('Name', :with => 'Harry Jones')
|
||||||
|
@session.click_button('awesome')
|
||||||
|
extract_results(@session)['name'].should == 'Harry Jones'
|
||||||
|
end
|
||||||
|
|
||||||
it "should fill in a textarea by id" do
|
it "should fill in a textarea by id" do
|
||||||
@session.fill_in('form_description', :with => 'Texty text')
|
@session.fill_in('form_description', :with => 'Texty text')
|
||||||
@session.click_button('awesome')
|
@session.click_button('awesome')
|
||||||
|
|
|
@ -11,6 +11,11 @@
|
||||||
<input type="text" name="form[last_name]" value="Smith" id="form_last_name"/>
|
<input type="text" name="form[last_name]" value="Smith" id="form_last_name"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label for="form_name">Name</label>
|
||||||
|
<input type="text" name="form[name]" value="John Smith" id="form_name"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="form_password">Password</label>
|
<label for="form_password">Password</label>
|
||||||
<input type="password" name="form[password]" value="seeekrit" id="form_password"/>
|
<input type="password" name="form[password]" value="seeekrit" id="form_password"/>
|
||||||
|
@ -102,8 +107,8 @@
|
||||||
|
|
||||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||||
<p>
|
<p>
|
||||||
<label for="form_name">Name</label>
|
<label for="form_file_name">File Name</label>
|
||||||
<input type="file" name="form[name]" id="form_name"/>
|
<input type="file" name="form[file_name]" id="form_file_name"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
Loading…
Reference in New Issue