Search code examples
htmlcsspuppeteerselector

Puppeteer.page.waitForSelector timeouts, even though the element is present


I am running the following code:

    const browserFetcher = puppeteer.createBrowserFetcher();
    //revision corresponds to Chrome 69.0.3497.92
    const revisionInfo = await browserFetcher.download('576753');
    const browser = await puppeteer.launch({
        executablePath: revisionInfo.executablePath,
        headless: false,
        ignoreHTTPSErrors: true,
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox'
        ]
    });
    const page = await browser.newPage();
    await page.goto(link, { waitUntil: 'networkidle2' });
    await page.waitForSelector('button.btn-primary', { visible: true });
    const thisLineIsNeverReached = 0;

The problem is that the const thisLineIsNeverReached = 0; line is never reached and the Puppeteer throws an error saying that the 'button.btn-primary' selector timed out.

I checked that the specified element is indeed present on a page: enter image description here

I am using the "puppeteer": "11.0.0" version.

So, why may Puppeteer not see the element?


Solution

  • Changing the:

    const revisionInfo = await browserFetcher.download('576753');
    const browser = await puppeteer.launch({
        executablePath: revisionInfo.executablePath,
        headless: false,
        ignoreHTTPSErrors: true,
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox'
        ]
    });
    

    to the:

    const browser = await puppeteer.launch({
        headless: false,
        ignoreHTTPSErrors: true,
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox'
        ]
    });
    

    and then changing all the references throughout the project from the puppeteer-core to the puppeteer solved the issue.

    Also, this approach allows not to keep a constant track of the latest revision. Puppeteer will download and use a correct revision automatically.