How to access page.getby* functions inside a PlaywrightCrawler #1672
-
I'm using import { chromium } from "@playwright/test";
const browser = await chromium.launch({
headless: true,
});
const context = await browser.newContext();
const page = await context.newPage();
for (let i = 0; i < brandSection.length; i++) {
let [brandName, brandCount] = brandSection[i].split("\n");
await page
.getByRole("button", { name: `${brandName} ${brandCount}` })
.click();
} So this works without crawlee, but when I try to use it inside a import { createPlaywrightRouter, enqueueLinks, Dataset } from "crawlee";
import { PlaywrightCrawler } from "crawlee";
....
....
router.addDefaultHandler(async ({ page, request, enqueueLinks }) => {
const prodGridSel = ".catalog-grid a";
//**here goes the code that uses page.getByRole()**//
await enqueueLinks({
...
},
});
...
...
const crawler = new PlaywrightCrawler({
requestHandler: router,
}); I haven't used playwright for testing, only for crawling with So, can I have a PS:I posted this in stackoverflow a week ago, but i haven't received any answers. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Others will probably update you about the method specifically, but Crawlee allows you to provide your own Playwright launcher so you should be able to use the "@playwright/test". It might crash though since we are not testing it. See https://crawlee.dev/api/playwright-crawler/interface/PlaywrightLaunchContext#launcher |
Beta Was this translation helpful? Give feedback.
Others will probably update you about the method specifically, but Crawlee allows you to provide your own Playwright launcher so you should be able to use the "@playwright/test". It might crash though since we are not testing it.
See https://crawlee.dev/api/playwright-crawler/interface/PlaywrightLaunchContext#launcher