Get a sibling web element using css selector

Viewed 1003

How can I get a reference to the button? which is always a sibling of the text I'm searching for.

In protractor test:

let spanText = 'My text';
let spanRef = element(by.css('span[name=' + spanText + ']'));

Html:

<div>
  <span name="My text">My text</span>
  <button type="button">
    Click me!
  </button>
</div>
2 Answers
Related