apify-docs icon indicating copy to clipboard operation
apify-docs copied to clipboard

Playwright example code is not locale specific

Open JJetmar opened this issue 3 years ago • 0 comments

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")');
...

JJetmar avatar Aug 01 '22 14:08 JJetmar