1
votes

I'm looking for the best way to validate an element within another element using Watir WebDriver. Example: I want to verify that the span below is is found within the anchor that contains it.

<a id="header-main-menu-home" href="/" class="tracked">
"Home" 
    <span class="arrow arrow-up"></span>
</a>

I'm currently using the location as validation, but do not think this is sustainable.

Any help is much appreciated?

1

1 Answers

4
votes

You can do:

browser.link(:id => 'header-main-menu-home').span(:class => 'arrow').present?

This will check that the link contains the span. This works because the locator of the span will stay within the scope of the link.