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).

For more info on working with DOM elements in Nightwatch, refer to the Finding & interacting with DOM Elements guide page.


                    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)


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

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


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

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