1

While using Puppeteer, a common error that occurs when some element is clicked is

Node is either not visible or not an HTMLElement

this has been addressed and solved here

however, the same solution fails for me when I try to simulate a double click using jQuery's dbclick() method

await page.evaluate(() => {
  document.querySelector('.some-selector').dbclick();
});

error: TypeError: document.querySelector(...).dbclick is not a function

why???

asus
  • 1,427
  • 3
  • 25
  • 59

1 Answers1

3

There is no dbclick method, only an event with that name.

So in puppeteer you would either use jquery:

await page.evaluate(() => {
  $('.some-selector').dbclick();
});

Or would create an event in plain javascript:

const selector = '.some-selector';
await page.evaluate(selector => {

    var targLink    = document.querySelector (selector);
    var clickEvent  = document.createEvent ('MouseEvents');
    clickEvent.initEvent ('dblclick', true, true);
    targLink.dispatchEvent (clickEvent);

}, selector)
Vaviloff
  • 16,282
  • 6
  • 48
  • 56
  • 1
    better to use `document.querySelector()` method. then you can pass any selector type ( class, id) – newbie Nov 11 '19 at 12:46
  • 1
    I like that solution! I can initialise clickEvent once per class and pass it to any element as dispatchEvent parameter – Dmitri Algazin Sep 16 '20 at 20:14