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

16 Replies, 1231 Views

Lol, the struggle is real! For how to locate element without using attributes, I’ve had luck with `querySelector` + `:contains` (jQuery-style) via JS.

Like:
```js
document.querySelector("div:contains('hello')")
```
Not pure CSS, but if you’re automating, Puppeteer/Playwright handle this.

Pro tip: If it’s a button or link, maybe use `getByRole` in Testing Library? Less flaky than text.

Messages In This Thread



Users browsing this thread: 1 Guest(s)