How to get id or item name in watir?

Watir can find the text on the page:

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

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

But how can I get the name or id of a range 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");

Does something like this exist in watir?

+3
source share
1 answer
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.

+4
source

Source: https://habr.com/ru/post/1742907/


All Articles