I'm using puppeteer to check for a specific text that appears on the webpage. My code to check is as follows:
if ((await page.waitForXPath('//span[contains(text(), "Subscription Confirmed")]',30000)) !== null) {
chk = await page.evaluate(el => el.innerText, await page.$x('//span[contains(text(), "Subscription Confirmed")]'))
chk = 'Success'
} else {
// do something else
chk = 'Failed'
}
This doesn't seem to detect the text for some reason. I have attached a screenshot of the DOM of the webpage where you can see the text - DOM. Hoping someone could help.
Try the following:
if ((await page.waitForXPath('//*[contains(text(), "Subscription Confirmed")]',30000)) !== null) {
chk = await page.evaluate(el => el.innerText, await page.$x('//*[contains(text(), "Subscription Confirmed")]'))
chk = 'Success'
} else {
chk = 'Failed'
}
This worked for me in a jest test:
await page.waitForXPath('//*[contains(text(), "SOME TEXT")]')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With