From 3361db1cc2c8550f8be04a6b972e46f012919a3a Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Fri, 31 Mar 2023 20:01:03 +0200 Subject: [PATCH] click on the checkbox --- package.json | 2 +- src/workers/CommandorPage.js | 57 +++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 6f2f350..99cbabc 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "node-schedule": "^2.1.0", "node-wget": "^0.4.3", "node-xlsx": "^0.21.0", - "playwright": "1.25.2", + "playwright": "^1.32.1", "read-ini-file": "^3.0.1", "winston": "^3.8.2", "yarn": "^1.22.19" diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 99595e3..04bfa4d 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -81,18 +81,23 @@ class CommandorPage { // Connect to the device. log("loadPage() called"); // await this.device.shell('am force-stop com.android.chrome'); - const context = await this.device.launchBrowser(); - // await context.clearCookies() + try { + this.context = await this.device.launchBrowser(); + // await context.clearCookies() + // Use BrowserContext as usual. + this.page = await this.context.newPage(); + this.page.on("load", (loadedPage) => { + this.onPageLoad(loadedPage) + }) - // Use BrowserContext as usual. - this.page = await context.newPage(); - this.page.on("load", (loadedPage) => { - this.onPageLoad(loadedPage) - }) + this.page.on("response", (response) => { + this.onResponse(response) + }) + } catch (e) { + log(e) + this.isTerminated = true + } - this.page.on("response", (response) => { - this.onResponse(response) - }) try { const item = searchTexts[Math.floor(Math.random() * searchTexts.length)]; await this.page.goto("https://www.google.com/search?q=" + item + "&lr=lang_en", {timeout: 90 * 1000}); @@ -104,15 +109,9 @@ class CommandorPage { try { if (this.page.url().includes("google")) this.page.locator('button >> nth=3').click() - // this.page.locator('button:has-text("Tout accepter")').click() } catch (e) { log(e) } - // try { - // this.page.locator('button:has-text("Accept all")').click() - // } catch (e) { - // log(e) - // } try { this.page.locator(':nth-match(:text("rendezvousparis"), 1)').click() } catch (e) { @@ -124,12 +123,17 @@ class CommandorPage { const intervalTask = setInterval(() => { if (this.isTerminated) { log(this.device.model() + ":request terminated, will close device"); - context.close(); + this.context.close(); // this.page.close() - this.device.close() + // this.device.close() clearInterval(intervalTask) cancel() - return context + return this.context + } else { + if (this.page.url() === RDV_URL) { + if (!this.isFillingFields) + this.fillFields(this.page); + } } }, 10 * 1000)//interval of 10 seconds @@ -316,6 +320,8 @@ class CommandorPage { let pageContent = await page.content() let hasCaptcha = pageContent.includes("g-recaptcha-response") if (hasCaptcha) { + await this.clickCheckbox() + await delay(1000) this.captchaSolver = new SolveCaptcha(page); await this.captchaSolver.start((solution) => { log("solution is: " + solution); @@ -370,8 +376,8 @@ class CommandorPage { } else { if (currentPage.url() === RDV_URL) { await this.fillFields(this.page); - if (this.isFillingFields) - await this.getErrors() + // if (this.isFillingFields) + // await this.getErrors() } else { if (content.includes(MESSAGE_URL_VALIDATION_FR) || content.includes(MESSAGE_URL_VALIDATION_EN)) { log("successful"); @@ -462,6 +468,15 @@ class CommandorPage { } } + async clickCheckbox() { + try { + // let errorItem = await this.page.click("#recaptcha-anchor > div.recaptcha-checkbox-border") + await this.page.frameLocator('[title="reCAPTCHA"]').getByRole('checkbox', {name: 'I\'m not a robot'}).click(); + } catch (e) { + log(e); + } + } + async handleError(errorContent) { log("handle error:" + errorContent); if (errorContent.includes(DOUBLE_REQUEST_ERROR_MESSAGE) || errorContent.includes(DOUBLE_REQUEST_ERROR_MESSAGE_FR)) {