previousElement
Returns the previous sibling element of the selected DOM-element.
Usage
$(selector).previousElement()
Examples
- Asynchronous Mode
- Synchronous Mode
index.html
<div class="parent">
<p>Sibling One</p>
<p>Sibling Two</p>
<p>Sibling Three</p>
</div>
previousElement.js
it('should get text from previous sibling element', async () => {
const elem = await $$('p');
const previousElem = await elem[1].previousElement()
console.log(await previousElem.getText()); // outputs: "Sibling One"
});
index.html
<div class="parent">
<p>Sibling One</p>
<p>Sibling Two</p>
<p>Sibling Three</p>
</div>
previousElement.js
it('should get text from previous sibling element', () => {
const elem = $$('p');
const previousElem = elem[1].previousElement()
console.log(previousElem.getText()); // outputs: "Sibling One"
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.