.getPreviousElementSibling() Suggest edits
Since: 3.0.0Returns 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.
Usage
browser.element(selector).getPreviousElementSibling()
Example
export default {
demoTest(browser: NightwatchAPI): void {
browser.element('.features-container li:second-child').getPreviousElementSibling().then(resultElement => {
console.log('previous sibling element Id:', resultElement.getId());
});
},
async demoTestAsync(browser: NightwatchAPI): Promise<void> {
const resultElement = await browser.element('.features-container li:second-child').getPreviousElementSibling();
console.log('previous sibling element Id:', resultElement.getId());
}
}
Returns
Type | description |
---|---|
ScopedWebElement |