Puppeteer - intermittent click failures

I am encountering a problem with the functionality of clickable elements in my Puppeteer script, and I can’t seem to resolve it.

Setup

  • TypeScript version: 2.9.0-insiders-20180510
  • Jest version: 22.4.3
  • Puppeteer version: 1.4.0
  • Operating System: Windows 10
  • Node.js version: 8.9.0

Code Example

await page.waitFor(selectorForActionButtons(2, 'Turn Off'));
console.log(await page.evaluate(() => document.body.innerHTML));
await page.click(selectorForActionButtons(2, 'Turn Off'));
await page.waitFor(selectorForActionButtons(2, 'Turn On'));

Issue

Occasionally, the clicking function does not perform as expected, even though the element is indeed present in the page’s HTML. I logged the content of the page and confirmed that the element appears, yet the click isn’t registered, and no errors are reported during this action.

Please let me know if you require any further information.

Try adding a small delay before clicking to ensure the element is stable. You can use Puppeteer’s page.waitForTimeout() method:

await page.waitFor(selectorForActionButtons(2, ‘Turn Off’));
await page.waitForTimeout(100); // Add a delay
await page.click(selectorForActionButtons(2, ‘Turn Off’));

This can resolve timing issues that occur when elements are visible but not fully interactive.