Reputation: 6675
I have some HTML like this:
<ul id="directory">
<li><a id="first" href="/first">first</a></li>
<li><a id="second" href="/second">second</a></li></ul>
I want to locate the link with id "second" based on its text and relationship to the ul with id "directory" and click on it using watir-webdriver.
It seems like should simply be able to say:
browser.ul(:id => 'directory').li.a(:text => 'second')
but this does not exist.
After researching, I thought maybe I should be doing it like this:
browser.ul(:id => 'directory').lis.a(:text => 'second')
but LICollection
doesn't even have an a
method. I think maybe I should be doing something with each
but I have no idea what it would be.
Is there a good way I can identify this element, without resorting to a CSS or XPath selector, using these criteria:
Upvotes: 0
Views: 165
Reputation: 350
browser.ul(:id => 'directory').a(:id => 'second')
Let me know is the above statement is working or not.
Upvotes: 0
Reputation: 46826
You can do:
browser.ul(:id => 'directory').a(:text => 'second')
In Watir-Webdriver, you do not need to specify the li element to get access to the link. As well, assuming a reasonably formed HTML page, any link in the ul element will be in the li element (ie I believe that the only allowed direct children of ul elements is li elements).
Upvotes: 2