ulixee / hero

The web browser built for scraping
MIT License
649 stars 32 forks source link

Locate element by text #191

Closed shstkvch closed 1 year ago

shstkvch commented 1 year ago

Hello, me again. I'm used to using this method in playwright to find an element by its text content:

await page.locator('text=Log in').click();

Is there an equivalent method in Hero? This would be a very useful feature

I'm aware I can find the element like this, but it feels a bit clunky: document.evaluate('//a[contains(., "Log in")]', document).iterateNext()

blakebyrnes commented 1 year ago

We don't have custom selectors yet. It's something we've talked about. I often use the $xpathSelector DOM extension for something similar: https://ulixee.org/docs/hero/basic-client/awaited-dom-extensions#xpathSelector

shstkvch commented 1 year ago

That's useful, thank you Blake. I suppose I could just wrap that in a little locate() utility function to make it a bit more usable for me.