works on xiaomi
This commit is contained in:
@@ -90,9 +90,10 @@ class CommandorPage {
|
|||||||
// Connect to the device.
|
// Connect to the device.
|
||||||
log("loadPage() called");
|
log("loadPage() called");
|
||||||
try {
|
try {
|
||||||
this.browser = await puppeteer.connect({browserWSEndpoint: 'ws://127.0.0.1:9002/devtools/browser',})
|
this.browser = await puppeteer.connect({
|
||||||
// await context.clearCookies()
|
browserWSEndpoint: 'ws://127.0.0.1:9002/devtools/browser',
|
||||||
// Use BrowserContext as usual.
|
headless: false, defaultViewport: null
|
||||||
|
})
|
||||||
this.page = await this.browser.newPage();
|
this.page = await this.browser.newPage();
|
||||||
|
|
||||||
this.page.on("load", (loadedPage) => {
|
this.page.on("load", (loadedPage) => {
|
||||||
@@ -126,9 +127,16 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// let element = await this.page.$(':nth-match(:text("rendezvousparis"), 1)')
|
// let element = await this.page.$(':nth-match(:text("rendezvousparis"), 1)')
|
||||||
await this.page.$eval(':nth-match(:text("rendezvousparis"), 1)', el => {
|
// let element = await this.page.$(':nth-match(:text("rendezvousparis"), 1)')
|
||||||
el.click()
|
const [button] = await this.page.$x("//a[contains(., 'rendezvousparis')]");
|
||||||
});
|
console.log("button is " + button)
|
||||||
|
if (button) {
|
||||||
|
console.log("will click on the button")
|
||||||
|
await button.click();
|
||||||
|
}
|
||||||
|
// await this.page.$eval(':nth-match(:text("rendezvousparis"), 1)', el => {
|
||||||
|
// el.click()
|
||||||
|
// });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e)
|
log(e)
|
||||||
if (!this.page.url().includes(RDV_URL)) {
|
if (!this.page.url().includes(RDV_URL)) {
|
||||||
@@ -202,7 +210,7 @@ class CommandorPage {
|
|||||||
if (!page.isClosed()) {
|
if (!page.isClosed()) {
|
||||||
if (!this.isPhoneInput) {
|
if (!this.isPhoneInput) {
|
||||||
await page.focus(PHONE_NUMBER);
|
await page.focus(PHONE_NUMBER);
|
||||||
await page.keyboard.type("+330" + this.contact.phoneNumber);
|
await page.keyboard.type("" + this.contact.phoneNumber);
|
||||||
this.isPhoneInput = true;
|
this.isPhoneInput = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,10 +262,20 @@ class CommandorPage {
|
|||||||
if (!page.isClosed()) {
|
if (!page.isClosed()) {
|
||||||
if (!this.cguChecked) {
|
if (!this.cguChecked) {
|
||||||
await page.focus(CGU_ID);
|
await page.focus(CGU_ID);
|
||||||
await page.click(CGU_ID);
|
await page.evaluate(() => {
|
||||||
|
if (!document.querySelector("#cgu").checked) {
|
||||||
|
document.querySelector("#cgu").checked = true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// await page.click(CGU_ID);
|
||||||
await delay(getRandomWaitTime());
|
await delay(getRandomWaitTime());
|
||||||
await page.focus(PROCESSING_ID);
|
await page.focus(PROCESSING_ID);
|
||||||
await page.click(PROCESSING_ID)
|
// await page.click(PROCESSING_ID)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
if (!document.querySelector("#processing").checked) {
|
||||||
|
document.querySelector("#processing").checked = true
|
||||||
|
}
|
||||||
|
});
|
||||||
this.cguChecked = true;
|
this.cguChecked = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,11 +336,10 @@ class CommandorPage {
|
|||||||
if (!this.page.isClosed()) {
|
if (!this.page.isClosed()) {
|
||||||
try {
|
try {
|
||||||
// remove debug flag
|
// remove debug flag
|
||||||
await this.removeDebugFlag()
|
// const validElement = await page.$('.btn');
|
||||||
const validElement = await page.$('.btn');
|
this.page.evaluate(() => {
|
||||||
// this.page.evaluate(() => {
|
document.getElementsByClassName("btn")[0].click();
|
||||||
// document.getElementsByClassName("btn")[0].click();
|
})
|
||||||
// })
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e)
|
log(e)
|
||||||
}
|
}
|
||||||
@@ -513,7 +530,7 @@ class CommandorPage {
|
|||||||
|
|
||||||
async onResponse(response) {
|
async onResponse(response) {
|
||||||
let rex = new RegExp(REGEX_RDV_URL)
|
let rex = new RegExp(REGEX_RDV_URL)
|
||||||
log("onResponse with url:" + response.url())
|
// log("onResponse with url:" + response.url())
|
||||||
// log("onResponse with url:" + response.body())
|
// log("onResponse with url:" + response.body())
|
||||||
if (rex.test(response.url())) {
|
if (rex.test(response.url())) {
|
||||||
log("rdv url found:" + response.url())
|
log("rdv url found:" + response.url())
|
||||||
@@ -574,12 +591,12 @@ class CommandorPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async clickCheckbox() {
|
async clickCheckbox() {
|
||||||
try {
|
// try {
|
||||||
// let errorItem = await this.page.click("#recaptcha-anchor > div.recaptcha-checkbox-border")
|
// // 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();
|
// await this.page.$('[title="reCAPTCHA"]').getByRole('checkbox', {name: 'I\'m not a robot'}).click();
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
log(e);
|
// log(e);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleError(errorContent) {
|
async handleError(errorContent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user