メインコンテンツにスキップ

parentElement

選択されたDOM要素の親要素を返します。

使用方法
$(selector).parentElement()
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 () => {
const elem = await $$('p');
const parent = await elem[2].parentElement()
console.log(await parent.getAttribute('class')); // outputs: "parent"
});
戻り値
  • <WebdriverIO.Element>

Welcome! How can I help?

WebdriverIO AI Copilot