khan
khan

Reputation: 547

How to access the following link element using Watir

For instance, if the link contains an <image> element as the text, then how do we access it using the watir:

For example:

<a><img src="" alt=""\></a>

So now I want to access the link using ("text-attribute") then how do we do these?

Upvotes: 2

Views: 2410

Answers (1)

Justin Ko
Justin Ko

Reputation: 46826

You could locate the image and then get the parent element:

browser.image(:alt => "").parent.click

Or you could find a link that contains the image:

browser.links.find{ |a| a.image(:alt => "").exists? }.click

If you really want to use the text, then you can use a :text => ''. The text locator only checks the visible text of the link - ie it ignores the image.

browser.link(:text => '').click

Upvotes: 2

Related Questions