Puppeteer in NodeJS reports ‘Error: Node is either not visible or not an HTMLElement’

Try doing this:

await button.evaluate(b => b.click());

instead of

await button.click();

The difference is that button.evaluate(b => b.click()) runs the JavaScript HTMLElement.click() method on the given element in the browser context, which will fire a click event on that element even if it’s hidden, off-screen or covered by a different element, whereas button.click() clicks using Puppeteer’s ElementHandle.click() which

  1. scrolls the page until the element is in view
  2. gets the bounding box of the element (this step is where the error happens) and finds the screen x and y pixel coordinates of the middle of that box
  3. moves the virtual mouse to those coordinates and sets the mouse to “down” then back to “up”, which triggers a click event on the element under the mouse

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)