Using Watir, is there a way to access an element without attributes?
For example:
<span>Text</span>
I’d like to avoid using xpath, but if that’s the only way it’s cool.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Disregarding the non-WATIR issues of having tags in the first place, or requesting unique attributes from your developers (or yourself), you can always access an element via its parent elements, or by index.
For example:
Text
You can work through however many unique elements you need to before reaching the child span element, without using Xpath. Of course, you only need one unique parent element to reach that specific child element, and you work down from that to the child.
Another example, assuming it is the nth span on the page:
@browser.span(:index => n)
The by-index approach is very brittle and prone to breaking when any update is made to the page, however.