Rayrun
← Back to Discord Forum

navigate upwards through Locator's parents multiple times

Hi!

I quite didn't get it from documentation how can I navigate upwards multiple time given that I have found the Locator by text.

For instance I do this and find the necessary Locator

page.getByText("Dropdown element with unique text on the webpage")

now I want to navigate upwards through parent elements a few times to get to the dropdown element, which can't be identifiable otherwise on the webpage.

This thread is trying to answer question "How can I navigate upwards multiple times through parent elements using a Locator in Playwright?"

1 reply

Just chain your locator with:

.locator('xpath=../')

If you need to go higher

.locator('xpath=../..')

You can also chain this with standard playwright locators (getByRole, etc) to navigate within your new scope.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].