I am facing an issue when trying to click on an element. The element is not a button but a div, and I am using the puppeteer-extra library. The element resembles a radio button in appearance (a circular selection option), but it is actually a div.
When I attempt to target and click on the element, I get the following error, and I need a solution as this has been quite frustrating. Here’s my code:
const elementHandle = await page.waitForSelector(selector, { timeout });
if (!elementHandle) {
throw new Error(`Element not found - Selector: ${selector}`);
}
await elementHandle.focus();
await elementHandle.click();
I tried using waitForSelector to locate the element and then performing a click on it after focusing. I expected the script to click on the element without issues, but instead, I encountered an error. I thought focusing on the element before clicking would solve the issue, but it didn’t work. I also tried adjusting the selector and timeout, but the problem persists.
My expectation was that the div would behave similarly to a button or radio element when clicked, as it looks like a radio button in design.
AbodProgammer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.