help
help copied to clipboard
How to detect which element appeared on page - Puppeteer/Nodejs
Details
i have the code below, and i'm trying to work with if, the thing is, i'm having issues to detect which function appeared on page and proceed with correctly steps, actually it detects the function inside of first if when it appears, but when the function of second if appear, it don't detect (or wait forever for first function?), then crash for function timeout, what should i do, to my script detect which one appeared and then to proceed with the correct steps to each detected function, cause only one of them appears per attempt, basically i need know which function appeared and choose which if will handle this function
also; im learning javascript
if someone can help me, i'll be thankful
Node.js version
Not applicable.
Example code
if (await page.waitForFunction('document.querySelector("body").innerText.includes("Configurando sua conta...")')){
console.log('Function 1 appeared, doing steps for function 1 (below)');
await page.waitForNavigation();
await page.waitForTimeout(100000);
await page.goto('website-secret');
}
if (await page.ForFunction('document.querySelector("body").innerText.includes("Você não está qualificado")')){
console.log('Function 2 appeared, doing steps for function 2 (below)')
await page.waitForTimeout(1200000);
await page.goto('website-secret');
}
Operating system
Windows 10
Scope
code
Module and version
Not applicable.
You seem to be using a non-existent method called ForFunction on the expression of the second if statement, it's supposed to be waitForFunction() unless you've forgotten to put that there in your example code.
There has been no activity on this issue for 11 months. The help repository works best when sustained engagement moves conversation forward. The issue will be closed in 1 month. If you are still experiencing this issue on the latest supported versions of Node.js, please leave a comment.
Closing after no activity on this issue for 12 months.