question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question]: retrieve DOM path for locator / element

See original GitHub issue

Your question

Hi,

Thanks for all the good work on Playwright 😉

I wonder if there is any way to retrieve the DOM path of a matched (through locator) HTML element?

Something like

foo = await page.locator("text=Sign up").click()
print(foo.dom_path()) # body > div#bar > div:nth-42 > p

Hope I make myself clear, thanks in advance

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
LeRitoncommented, Jun 20, 2022

This is awesome and thus your are awesome! Will have a look on this, thanks 😉

0reactions
alexferrari88commented, Jun 17, 2022

Hi Alex,

Seems like a perfect match, except for one part: I work with Playwright Python. Do you know if there is a way to plug a JS plugin to my existing codebase?

there you go: https://pypi.org/project/playwright-dompath/ Source at: https://github.com/alexferrari88/playwright-dompath-py

you are welcome 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Locating DOM elements using selectors - Web APIs | MDN
The Selectors API provides methods that make it quick and easy to retrieve Element nodes from the DOM by matching against a set...
Read more >
Get the DOM path of the clicked <a> - javascript - Stack Overflow
Here is a solution for exact matching of an element. It is important to understand that the selector (it ...
Read more >
How To Access Elements in the DOM - DigitalOcean
The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID...
Read more >
How to locate an element on the page - Web Performance
What is an Element? Everything you see on the page is an element. · What is an Element Locator? · How does each...
Read more >
Locators in Selenium- How To Locate Elements On Web-page?
If you wish to learn the easiest way to locate elements on a webpage, you can check out the Selenium Certification. Locating elements...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found