It is being assumed that the element and label belong to the same container, 
which might not be true when chaining elements.

Given the html:

````html
<div>
  <span class="label">
    <label for="my_label">My Label</label>
  </span>
  <span class="field">
    <input type="text" name="my_label" id="my_label"/>
  </span>
</div>
````

You can find the text field by its label when the container of the text field 
includes the label:

````ruby
p browser.text_field(:label => 'My Label').exists?
#=> true

p browser.text_field(:name => 'my_label').label
#=> "My Label"
````

However, if you reduce the container to only include the text field, the label 
is no longer found:

````ruby
p browser.span(:class => 'field').text_field(:label => 'My Label').exists?
#=> false

p browser.span(:class => 'field').text_field(:name => 'my_label').label
#=> `assert_exists': Unable to locate element, using {:tag_name=>["label"], 
:for=>"my_label"} (Watir::Exception::UnknownObjectException)
````

---
Reply to this email directly or view it on GitHub:
https://github.com/watir/watir-classic/issues/60
_______________________________________________
Wtr-development mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-development

Reply via email to