click on the checkbox

This commit is contained in:
2023-03-31 20:01:03 +02:00
parent c036311afa
commit 3361db1cc2
2 changed files with 37 additions and 22 deletions
+36 -21
View File
@@ -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)) {