Skip to main content

getElement

Overview​

Resolve a chainable element reference into its element object to read properties such as selector and elementId.

Usage​

element.getElement()

Parameters​

This command has no parameters.

Result​

Promise<WebdriverIO.Element>: the current element object, including its methods and metadata.

Limitations​

This is not a new protocol search, a DOM snapshot or a wait for visibility. The wrapper returns the current element object; do not assume that an elementId remains valid after navigation or DOM replacement.

Example​

Set baseUrl to a local HTTP test site where / serves an HTML page. Run the example in a Testplane test file.

const assert = require("node:assert/strict");

it("getElement: inspect a resolved element object", async ({ browser }) => {
await browser.url("/");
await browser.execute(() => {
document.body.innerHTML = '<button id="save">Save</button>';
});
const element = await browser.$("#save").getElement();
assert.equal(element.selector, "#save");
assert.equal(typeof element.elementId, "string");
assert.equal(await element.getText(), "Save");
});

See also​