Skip to content

Commit bea9020

Browse files
committed
eg: EG_MOBILE: fix Error: Can't query n-th element
1 parent cf64205 commit bea9020

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

epic-games.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,15 @@ try {
162162
for (const url of urls) {
163163
if (cfg.time) console.time('claim game');
164164
await page.goto(url); // , { waitUntil: 'domcontentloaded' });
165-
const purchaseBtn = page.locator('button[data-testid="purchase-cta-button"] >> :has-text("e"), :has-text("i")').first(); // when loading, the button text is empty -> need to wait for some text {'get', 'in library', 'requires base game'} -> just wait for e or i to not be too specific; :text-matches("\w+") somehow didn't work - https://github.com/vogler/free-games-claimer/issues/375
166-
await purchaseBtn.waitFor();
165+
// when loading, the button text is empty -> need to wait for some text {'get', 'in library', 'requires base game'} -> just wait for e or i to not be too specific; :text-matches("\w+") somehow didn't work - https://github.com/vogler/free-games-claimer/issues/375
166+
// was using locator('...').first().waitFor(), but that at some point led to exception locator.waitFor: Error: Can't query n-th element
167+
await page.waitForFunction(
168+
() => {
169+
const btn = document.querySelector('button[data-testid="purchase-cta-button"]');
170+
return btn && btn.textContent && /[ei]/i.test(btn.textContent);
171+
}
172+
);
173+
const purchaseBtn = page.locator('button[data-testid="purchase-cta-button"]').first();
167174
const btnText = (await purchaseBtn.innerText()).toLowerCase(); // barrier to block until page is loaded
168175

169176
// click Continue if 'This game contains mature content recommended only for ages 18+'

0 commit comments

Comments
 (0)