How to locate element without using attributes - Any reliable methods? or What are the best ways to l

16 Replies, 1236 Views

If you’re automating, try `page.$x("//*[contains(., 'your text')]")` in Puppeteer. Works when how to locate element without using attributes is a nightmare.

Or, if the element’s near something identifiable, use `near` in Playwright:
```js
page.locator(':near(:text("Username"), 100px)')
```

Tool: [Playwright docs](https://playwright.dev/docs/locators) have more tricks.

Messages In This Thread



Users browsing this thread: 1 Guest(s)