-1

Is there any method (didn't find in API) or solution to click on element with text?

For example I have HTML:

<div class="_5THWM1">flex
<span class="_2i7N3j">Sort By</ span>
<div class="_10UF8M 3LsR0e>Relevance</div>
<div class="_10UF8M">Popularity</div>
<div class-"_10UF8M'>Price -- Low to High</div>
<div class="_10UF8M>Price -- High to Low</div>
<div class="_10UF8M" >Newest First</div>
</div>

I want to click on Price -- Low to high but with the same classes I don't know how to click and I don't know how to click on text. Can anyone help me with this, please?

I am using Puppeteer and please write code to this.

  • 1
    How to click an element is [clearly documented](//github.com/puppeteer/puppeteer/blob/main/docs/api.md#elementhandleclickoptions). Is the problem _finding_ the element? – Sebastian Simon Nov 22 '21 at 06:39
  • Does this answer your question? [How to click on element with text in Puppeteer](https://stackoverflow.com/questions/47407791/how-to-click-on-element-with-text-in-puppeteer) – ggorlen Nov 23 '21 at 17:47

1 Answers1

0

Not really but you can use xpath or you can use find:

page.$$eval('div', divs => divs.find(div => div.innerText.match(/some text')).click())
pguardiario
  • 53,827
  • 19
  • 119
  • 159