Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor: How to locate a sibling of a given element?

<div>
   <a href='...'>LINK</a>
   <img class='image' />
</div>
<div>
   ...
</div>

I want to get a protractor element for the img tag with image class. I already know the link text 'LINK'. In other words, "How do I locate a sibling of a given element?".

The first line of the code could look like this:

browser.findElement(by.linkText('LINK'))

Any ideas?

Thanks & Cheers

like image 528
user1879408 Avatar asked May 18 '14 09:05

user1879408


1 Answers

Thanks for the inspiration. Here's my solution, not the one I was hoping for, but it works:

element(by.css('???')).element(by.xpath('..')).element(by.css('???')).click();

The chaining and the by.xpath, which allows to get back to the parent are the keys of the solution.

like image 190
user1879408 Avatar answered Oct 11 '22 20:10

user1879408