Skip to main content

parentElement

Overview

Use the parentElement command to get the parent element of the selected DOM element.

Usage

await browser.$(selector).parentElement();

Usage Examples

index.html

<div class="parent">
<p>Sibling One</p>
<p>Sibling Two</p>
<p>Sibling Three</p>
</div>

parentElement.js

it("should get class from parent element", async ({ browser }) => {
const elem = await browser.$$("p");
const parent = await elem[2].parentElement();

console.log(await parent.getAttribute("class")); // outputs: "parent"
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.