tags:

views:

37

answers:

1

Watir can find a text on a page:

<span id="i1" name="n1>Some Text</span>

e.text.include?("Some Text")

But how can I get the name or id of the span, when I only know "Some Text"

e.text.findInPage("Some Text").parentElement.id (should be "i1")
e.text.findInPage("Some Text").parentElement.name (should be "n1");

Something like this exists in watir?

+1  A: 
browser.span(:text => "Some Text").id
=> "i1"

browser.span(:text => "Some Text").name
=> "n1"

Tested on Windows, Ruby 1.8.6, Watir 1.6.5, Internet Explorer driver.

Željko Filipin