From 85513031f2d03478a9ed833cc4e9fa9a8fd24ed4 Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Fri, 23 Jun 2023 01:21:42 +0200 Subject: [PATCH] =?UTF-8?q?pg:=20external:=20fix=20lost=20elementHandle?= =?UTF-8?q?=C2=A0error=20due=20to=20navigation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit elementHandle.$: Protocol error (Page.adoptNode) --- prime-gaming.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/prime-gaming.js b/prime-gaming.js index c731efa..c99eec0 100644 --- a/prime-gaming.js +++ b/prime-gaming.js @@ -102,7 +102,7 @@ try { console.log('Number of already claimed games (total):', await games.locator('p:has-text("Collected")').count()); // can't use .all() since the list of elements via locator will change after click while we iterate over it const internal = await games.locator('[data-a-target="claim-prime-offer-card"]:has-text("Claim")').elementHandles(); - const external = await games.locator('[data-a-target="learn-more-card"]:has(p:text-is("Claim"))').elementHandles(); + const external = games.locator('[data-a-target="learn-more-card"]:has(p:text-is("Claim"))'); // using .elementHandles() here would lead to error due to page navigation: elementHandle.$: Protocol error (Page.adoptNode) console.log('Number of free unclaimed games (Prime Gaming):', internal.length); // claim games in internal store for (const card of internal) { @@ -118,9 +118,9 @@ try { const p = path.resolve(cfg.dir.screenshots, 'prime-gaming', 'internal', `${filenamify(title)}.png`); await card.screenshot({ path: p }); } - console.log('Number of free unclaimed games (external stores):', external.length); + console.log('Number of free unclaimed games (external stores):', await external.count()); // claim games in external/linked stores. Linked: origin.com, epicgames.com; Redeem-key: gog.com, legacygames.com, microsoft - for (const card of external) { + for (const card of await external.elementHandles()) { // TODO refactor (result of external locator changes with each iteration) // if (!card) continue; const title = await (await card.$('.item-card-details__body__primary')).innerText(); console.log('Current free game:', title);