On a page I'm scraping with Puppeteer, I have a list with the same id for every li
. I am trying to find and click on an element with specific text within this list. I have the following code:
await page.waitFor(5000)
const linkEx = await page.$x("//a[contains(text(), 'Shop')]")
if (linkEx.length > 0) {
await linkEx[0].click()
}
Do you have any idea how I could replace the first line with waiting for the actual text 'Shop'
?
I tried await page.waitFor(linkEx)
, waitForSelector(linkEx)
but it's not working.
Also, I would like to replace that a
in the second line of code with the actual id (#activities
) or something like that but I couldn't find a proper example.
Could you please help me with this issue?