Monday 16 November 2020

Puppeteer unable to click on a dynamically added overlay button

I'm extremely new to javascript so this might be a basic question.

I am using Puppeteer to attempt to scrape a webpage and download the video on the page. I am using the video downloader extension to fetch the video url. My idea is to automate the opening of the page on the browser and clicking on the video download button (generated by the extension) to download the video. But I'm having some issues with it:

I need to play the video for the download button to appear. I am able to do this by clicking on the play button using puppeteer. However, I am unable click on this new download button generated by the extension, on the video, after the video starts to play. I can visually see the button but Puppeteer is crashing with the error:

No node found for selector: button[class="ext_dl-button rounded-box"]

I think this is happening because the download button added by the extension is added dynamically to the webpage and the puppeteer page object does not know about it.

Any help to make puppeteer click on the download button generated by the extension would be appreciated. :)

Below is the part of the code I've written to scrape the website.

(async () => {
    const customArgs = [
        `--load-extension=${pathToExt}`
    ];
    browser = await puppeteer.launch({
        headless:false,
        ignoreDefaultArgs: ["--disable-extensions","--enable-automation"],
        args: customArgs,
    });
    page = await browser.newPage();
    await page.setViewport({
        width: 1280,
        height: 720,
        deviceScaleFactor: 1,
    });
    await page.goto('https://www.raywenderlich.com/sessions/new');
    console.log("Logging in...\n")
    await page.type('input[name="username"]',username,{delay:100})
    await page.type('input[name="password"]',password,{delay:80})

    await Promise.all([
        page.click('button[type="submit"]'),
        page.waitForNavigation()
    ])

    await Promise.all([
        page.goto('https://www.raywenderlich.com/8984-mvvm-on-android/lessons/1'),
        page.waitForNavigation()
    ])

    await sleep(3000)
    await page.click('button[class="o-button o-button-video-start"]')

    await sleep(3000)
    await page.click('button[class="ext_dl-button rounded-box"]')

    await sleep(10000000)

    await browser.close();
})();


from Puppeteer unable to click on a dynamically added overlay button

No comments:

Post a Comment