From d9e91d22c9f01114f905b8edf6e7322bb56639be Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Thu, 1 Aug 2024 15:46:41 +0200 Subject: [PATCH] eg: fix changed button locators --- epic-games.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/epic-games.js b/epic-games.js index 9d492a0f..ff8f3e01 100644 --- a/epic-games.js +++ b/epic-games.js @@ -156,7 +156,8 @@ try { for (const url of urls) { if (cfg.time) console.time('claim game'); await page.goto(url); // , { waitUntil: 'domcontentloaded' }); - const btnText = await page.locator('//button[@data-testid="purchase-cta-button"][not(contains(.,"Loading"))]').first().innerText(); // barrier to block until page is loaded + const purcahseBtn = page.locator('aside button').first(); + const btnText = (await purcahseBtn.innerText()).toLowerCase(); // barrier to block until page is loaded // click Continue if 'This game contains mature content recommended only for ages 18+' if (await page.locator('button:has-text("Continue")').count() > 0) { @@ -187,12 +188,12 @@ try { const notify_game = { title, url, status: 'failed' }; notify_games.push(notify_game); // status is updated below - if (btnText.toLowerCase() == 'in library') { + if (btnText == 'in library') { console.log(' Already in library! Nothing to claim.'); notify_game.status = 'existed'; db.data[user][game_id].status ||= 'existed'; // does not overwrite claimed or failed if (db.data[user][game_id].status.startsWith('failed')) db.data[user][game_id].status = 'manual'; // was failed but now it's claimed - } else if (btnText.toLowerCase() == 'requires base game') { + } else if (btnText == 'requires base game') { console.log(' Requires base game! Nothing to claim.'); notify_game.status = 'requires base game'; db.data[user][game_id].status ||= 'failed:requires-base-game'; @@ -205,7 +206,7 @@ try { urls.push(url); // add add-on itself again } else { // GET console.log(' Not in library yet! Click GET.'); - await page.click('[data-testid="purchase-cta-button"]', { delay: 11 }); // got stuck here without delay (or mouse move), see #75, 1ms was also enough + await purcahseBtn.click({ delay: 11 }); // got stuck here without delay (or mouse move), see #75, 1ms was also enough // click Continue if 'Device not supported. This product is not compatible with your current device.' - avoided by Windows userAgent? page.click('button:has-text("Continue")').catch(_ => { }); // needed since change from Chromium to Firefox? @@ -252,7 +253,7 @@ try { await iframe.locator('button:has-text("Place Order"):not(:has(.payment-loading--loading))').click({ delay: 11 }); // I Agree button is only shown for EU accounts! https://github.com/vogler/free-games-claimer/pull/7#issuecomment-1038964872 - const btnAgree = iframe.locator('button:has-text("I Agree")'); + const btnAgree = iframe.locator('button:has-text("I Accept")'); btnAgree.waitFor().then(() => btnAgree.click()).catch(_ => { }); // EU: wait for and click 'I Agree' try { // context.setDefaultTimeout(100 * 1000); // give time to solve captcha, iframe goes blank after 60s?