I am trying to do right click in all links in a page but is not working. I want to do right click because i have to test some events for mousedown, so i dont have to do necesarily click on them. I use right click so the links dont reload the page o redirect
(async () => {
const url = 'yourUrlHere';
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(url);
// test1
const elHandleArray = await page.$$('a');
for (const el of elHandleArray) {
console.log('### Clicking...' + el);
await el.evaluate(b => b.click({ button: "right", }));
//await el.click({ button: "right" });
}
// test2
await page.evaluate(() => {
const elHandleArray = document.querySelectorAll('a');
for (const el of elHandleArray) {
console.log('### Clicking...' + el);
el.click({ button: "right" });
}
});
// test3
const aElems = await page.$$('a');
for (let i = 0; i < aElems.length; i++) {
const elem = aElems[i];
console.log('### Click element: ', i);
await page.waitForTimeout(elem);
await page.evaluate((e) => {
document.querySelector(e).click({ button: "right", });
}, elem);
}
})();