I am trying to automate a login process into one of my accounts and this website has some weird password table that I have to click on to type my password , but when I select a button from the table and try to click on it I get the error:
throw new Error(‘Node is either not clickable or not an HTMLElement’)
the line that is causing the error is : ** button.click()**
here is the code :
const puppeteer= require("puppeteer")
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const pwd=["123456", "dadhaiudhw", "3712893jdhusydiu", "12kd9", "12!@#@4dmsak"]
const test= async ()=>{
const browser= await puppeteer.launch({headless: false})
const page= await browser.newPage()
await page.goto("https://ebanking.cpa-bank.dz/customer/")
const inputElement = await page.$('#form\:username');
await inputElement.type("96391281", {delay:100});
await sleep(Math.random()*4200)
const nextButton= await page.$("#form\:submit")
await nextButton.click()
await page.waitForSelector(".keypad-key")
const buttons = await page.$$('.keypad-key');
for(let button of buttons){
let valueHandle = await button.getProperty('textContent');
let btnText = await valueHandle.jsonValue();
if(btnText==="Shift"){
button.click()
}
}
}
test()
2
Answers
From a quick glance of the situation, puppeteer just might not pass all the necessary checks that the website has on that button, the security might be past the complexity of puppeteer which is causing puppeteer to throw a default error.
Obviously puppeteer has to programmatically generate those clicks to what they think will be needed to click buttons, a solution to this would be to either do this without puppeteer or to read the code on the button event listener and see what it is checking for and then compare that to how puppeteer is dispatching their spoofed clicks.
This line is also causing the problem in your code,
You should split the password into characters, then loop through it clicking on the keypad keys that match the characters in the password. Using XPATH you can get elements that contain a text e.g.
//button[contains(@class,"keypad-key") and text()="a"]
selects button with class keypad-key, which has text contenta
,Code :