apify-docs
apify-docs copied to clipboard
Playwright example code is not locale specific
Based on example in documentation (code).
Since there is not specified locale value for English in example's code, Playwright will set HTTP request header accept-language based on OS localization by default. In my case it was cs-CZ,cs;q=0.9, which lead to google page being in czech localization and since there was not button with "I agree" label, the program failed.
Even in en-GB, there is no button with "I agree" label, only "Accept all" and "Reject all" (probably changed due time).
I was able only to make it work with en-GB - ~~en-US~~ didn't work for some reason.
Possible solution:
...
// Set option locale to be sure the request is for english version of the page
const page = await browser.newPage({ locale: 'en-GB' });
await page.goto('https://google.com/');
// Click the "Accept all" button
await page.click('button:has-text("Accept all")');
...