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

user1879408 picture user1879408 · May 18, 2014 · Viewed 13.6k times · Source
<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

Answer

user1879408 picture user1879408 · May 20, 2014

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.