main.captcha.js: try beta of playwright-extra recaptcha, but fails on selectors
page.click: Evaluation failed: DOMException: Failed to execute 'querySelectorAll' on 'Document': 'button:has-text("Continue")' is not a valid selector.
This commit is contained in:
parent
c1393e95be
commit
d44d84be3c
5 changed files with 1555 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
auth.json
|
auth.json
|
||||||
|
.env
|
||||||
|
|
|
||||||
47
main.captcha.js
Normal file
47
main.captcha.js
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
const { existsSync } = require('fs');
|
||||||
|
if (!existsSync('auth.json')) {
|
||||||
|
console.error('Missing auth.json! Run `npm login` to login and create this file by closing the opened browser.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { chromium } = require('playwright-extra')
|
||||||
|
|
||||||
|
// add recaptcha plugin and provide it your 2captcha token (= their apiKey)
|
||||||
|
// Please note: You need to add funds to your 2captcha account for this to work
|
||||||
|
// https://2captcha.com?from=13225256
|
||||||
|
const RecaptchaPlugin = require('@extra/recaptcha')
|
||||||
|
const RecaptchaOptions = {
|
||||||
|
visualFeedback: true, // colorize reCAPTCHAs (violet = detected, green = solved)
|
||||||
|
provider: {
|
||||||
|
id: '2captcha',
|
||||||
|
token: process.env.API_KEY, // put your API_KEY=... in .env
|
||||||
|
},
|
||||||
|
}
|
||||||
|
chromium.use(RecaptchaPlugin(RecaptchaOptions));
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const browser = await chromium.launch({
|
||||||
|
headless: false,
|
||||||
|
executablePath: 'node_modules/puppeteer/.local-chromium/mac-938248/chrome-mac/Chromium.app/Contents/MacOS/Chromium', // why does it fail without?
|
||||||
|
});
|
||||||
|
const context = await browser.newContext({
|
||||||
|
storageState: 'auth.json',
|
||||||
|
viewport: { width: 1280, height: 1280 },
|
||||||
|
});
|
||||||
|
const page = await context.newPage();
|
||||||
|
await page.goto('https://www.epicgames.com/store/en-US/free-games');
|
||||||
|
// await expect(page.locator('a[role="button"]:has-text("Sign In")')).toHaveCount(0);
|
||||||
|
await page.click('button:has-text("Accept All Cookies")'); // to not waste screen space in --debug
|
||||||
|
await page.click('[data-testid="offer-card-image-landscape"]');
|
||||||
|
// TODO check if already claimed
|
||||||
|
await page.click('[data-testid="purchase-cta-button"]');
|
||||||
|
await page.click('button:has-text("Continue")');
|
||||||
|
// it then creates an iframe for the rest
|
||||||
|
// await page.frame({ url: /.*store\/purchase.*/ }).click('button:has-text("Place Order")'); // not found because it does not wait for iframe
|
||||||
|
const iframe = page.frameLocator('.webPurchaseContainer iframe')
|
||||||
|
await iframe.locator('button:has-text("Place Order")').click();
|
||||||
|
await iframe.locator('button:has-text("I Agree")').click();
|
||||||
|
// await page.pause();
|
||||||
|
await page.solveRecaptchas();
|
||||||
|
await context.close();
|
||||||
|
await browser.close();
|
||||||
|
})();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test'; // only npm dep needed for this file
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
|
|
||||||
if (!existsSync('auth.json')) {
|
if (!existsSync('auth.json')) {
|
||||||
|
|
|
||||||
1500
package-lock.json
generated
1500
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -3,9 +3,14 @@
|
||||||
"login": "npx playwright open --save-storage=auth.json https://www.epicgames.com/login",
|
"login": "npx playwright open --save-storage=auth.json https://www.epicgames.com/login",
|
||||||
"codegen": "npx playwright codegen --load-storage=auth.json https://www.epicgames.com/store/en-US/free-games",
|
"codegen": "npx playwright codegen --load-storage=auth.json https://www.epicgames.com/store/en-US/free-games",
|
||||||
"start": "npx playwright test --timeout 10000",
|
"start": "npx playwright test --timeout 10000",
|
||||||
"debug": "npx playwright test --debug"
|
"debug": "npx playwright test --debug",
|
||||||
|
"captcha": "node main.captcha"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.17.1"
|
"@extra/recaptcha": "^4.2.1-next.616",
|
||||||
|
"@playwright/test": "^1.17.1",
|
||||||
|
"dotenv": "^10.0.0",
|
||||||
|
"playwright": "^1.17.1",
|
||||||
|
"playwright-extra": "^4.2.1-next.616"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue