I have the following:
<ul class="a">
<li class="b">
<a class="c">
<span class="d">
<strong>text</strong>
</span>
</a>
</li>
</ul>
I'm trying to get the "text" from the span.
When I try:
puts browser.ul( :class =>'a').li( :class =>'b').link(:class =>'c').span(:class =>'d')
I get the span
element back. #<Watir::Span:0x007fa1d11edb18>
as i should.
But when trying:
puts browser.ul( :class =>'a').li( :class =>'b').link(:class =>'c').span(:class =>'d').text
im getting an error saying :
unable to locate element, using {:class=>'b', :tag_name=>"li"}
Any ideas ?
It would help if you could point to the page where the problem is reproducible, even if that means that you create a page yourself, put it in dropbox and make it public.
Did you even try to replicate the problem with the html and ruby code that you have posted? I am asking because the problem is not reproducible with the provided code. Take a look yourself:
> browser.ul( :class =>'a').li( :class =>'b').link(:class =>'c').span(:class =>'d')
=> #<Watir::Span:0x..fa66c75ff618434cc located=false selector={:class=>"d", :tag_name=>"span"}>
> browser.ul( :class =>'a').li( :class =>'b').link(:class =>'c').span(:class =>'d').text
=> "text"
As far as I understood, you are surprised that when you provide some code, Watir returns an element, but when you want to execute a method on the element, it complains that it can not find the element.
Take a closer look at the ruby object that represents element on a page:
#<Watir::Span:0x..fa66c75ff618434cc located=false selector={:class=>"d", :tag_name=>"span"}>
Please notice located=false
. As far as I know, that means that watir creates a ruby object before trying to access it, so the first line of your code does not raise any exceptions. But then when you try to use the element, watir can not find it on the page and complains.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With