简体   繁体   中英

How to click on text in Puppeteer?

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.

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())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM