.Element() Suggest edits
Search for an element on the page, starting from the identified element. The located element will be returned as a Web Element JSON object.
This command operates on a protocol level and requires a Web Element ID. Read more on Element retrieval on the W3C WebDriver spec page.
For more info on working with DOM elements in Nightwatch, refer to the Finding & interacting with DOM Elements guide page.Please note that this command operates on a protocol level and accepts the Web Element ID as the parameter. To retrieve it, use either the .findElement()
or .findElements()
command. Read more on Element retrieval.
Usage
.elementIdElement(webElementId, using, value, [callback])
Example
module.exports = {
'demo Test' : function(browser) {
browser.elementIdElement('<WebElementId>', 'css selector', '.new-element', function(result) {
console.log(result.value)
});
},
'es6 async demo Test': async function(browser) {
const result = await browser.elementIdElement('<WebElementId>', 'css selector', '.new-element');
console.log(result.value);
},
'page object demo Test': function (browser) {
var nightwatch = browser.page.nightwatch();
nightwatch.navigate();
const navbarHeader = nightwatch.section.navbarHeader;
navbarHeader.api.elementIdElement('@versionDropdown', 'css selector', 'option', function(result) {
browser.assert.ok(client.WEBDRIVER_ELEMENT_ID in result.value, 'The Webdriver Element Id is found in the result');
});
}
}
Parameters
Name | Type | description |
---|---|---|
webElementId |
string | The Web Element ID of the element to route the command to. |
using |
string | The locator strategy to use. |
value |
string | The search target. |
callback |
function | Callback function which is called with the result value. |