Apify Discord Mirror

Updated 5 months ago

enqueueLinksByClickingElements help

At a glance

The community member has written code using Puppeteer to enqueue links by clicking on elements with the selector 'a.js-color-change', but they are encountering an error. The error message indicates that the page property is expected to be an object, but it is undefined. Another community member suggests that the page and requestQueue objects need to be passed as well, and provides an example code snippet that demonstrates how to do this.

Useful resources
I have written this code for Puppeteer:
Plain Text
await puppeteerClickElements.enqueueLinksByClickingElements({ forefront: true, selector: 'a.js-color-change' })

But it generates this error:
Plain Text
 Reclaiming failed request back to the list or queue. Expected property `page` to be of type `object` but received type `undefined`
Expected object `page` to have keys `["goto","evaluate"]` in object `options`

Where is the mistake ?
N
P
6 comments
You need to pass the page and requestQueue as well https://docs.apify.com/sdk/js/docs/1.3/api/puppeteer
Plain Text
import { Dataset, createPuppeteerRouter, utils } from 'crawlee';

export const router = createPuppeteerRouter();

router.addHandler('detail', async ({ request,sendRequest, crawler, page, log,  }) => {

    await utils.puppeteer.enqueueLinksByClickingElements({
        page,
        requestQueue: crawler.requestQueue,
        selector: 'a.js-color-change'
        forefront: true
    })

});
Add a reply
Sign up and join the conversation on Discord