Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playwright test library - parent element for selector

please, how to get a parent element for a text selector by the Playwright E2E library.

Is better to modify the selector (it is string by something like >> //:parent) or evaluate the selector and then call the DOM element?

(The selector content is unknown)

Thank you.

like image 846
Tomas Randus Avatar asked May 14 '26 12:05

Tomas Randus


1 Answers

You can call .$ to start searching from the element:

const elem = await page.$(anySelector)
const parent = await elem.$('xpath=..')

Doc: https://playwright.dev/docs/api/class-elementhandle#elementhandleselector

like image 159
Tomas Randus Avatar answered May 19 '26 04:05

Tomas Randus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!