eg: set cookie instead of click 'Accept All Cookies'

This commit is contained in:
Ralf Vogler 2022-10-06 23:33:39 +02:00
parent 094662aefc
commit 2012c7e2f2

View file

@ -54,10 +54,12 @@ const page = context.pages().length ? context.pages()[0] : await context.newPage
// console.debug('userAgent:', await page.evaluate(() => navigator.userAgent));
try {
await context.addCookies([{name: 'OptanonAlertBoxClosed', value: '2022-10-06T21:15:28.081Z', domain: '.epicgames.com', path: '/'}]);
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // 'domcontentloaded' faster than default 'load' https://playwright.dev/docs/api/class-page#page-goto
// Accept cookies to get rid of banner to save space on screen. Will only appear for a fresh context, so we don't await, but let it time out if it does not exist and catch the exception. clickIfExists by checking selector's count > 0 did not work.
page.click('button:has-text("Accept All Cookies")').catch(_ => { }); // _ => console.info('Cookies already accepted')
// Accept cookies to get rid of banner to save space on screen. Clicking this did not always work since the message was animated in too slowly.
// page.click('button:has-text("Accept All Cookies")').catch(_ => { }); // not needed anymore since we set the cookie above
while (await page.locator('a[role="button"]:has-text("Sign In")').count() > 0) { // TODO also check alternative for signed-in state
console.error("Not signed in anymore. Please login and then navigate to the 'Free Games' page. If using docker, open http://localhost:6080");