Returns the element immediately preceding the specified one in its parent's child elements list. The element will be returned as web element JSON object (with an added .getId() convenience method).


browser.getPreviousSibling('#web-button', function(result) { 
await browser.getPreviousSibling('#web-button')
await browser.getPreviousSibling({selector: '#web-button', locateStrategy: 'css selector'})
// with global element():
const formEl = element('form');
const result = await browser.getPreviousSibling(formEl)
// with Selenium By() locators
const locator = by.tagName('form');
const result = await browser.getPreviousSibling(locator)
// with browser.findElement()
const formEl = await browser.findElement('form');
const result = await browser.getPreviousSibling(formEl)


Name Type description
selector string|object

The selector (CSS/Xpath) used to locate the element. Can either be a string or an object which specifies element properties.

callback function

Callback function which is called with the result value.


Type description
object The resolved element object, which contains a convenience .getId() method that can be used to retrieve the element ID


module.exports = {
 'demo Test': function(browser) {
    const resultElement = await browser.getPreviousSibling('.features-container li:second-child');

    console.log('previous sibling element Id:', resultElement.getId());

Recommended content