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

Usage

browser.getPreviousSibling('#web-button', function(result) { 
  console.log(result.value)
}})
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
// https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_By.html
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)

Parameters

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.

Returns

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

Example

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