Here is a code snippet in Puppeteer that simulates a click on a button:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
// Find the button element to click
const button = await page.$('button');
// Simulate a click on the button element
await button.click();
// Close the browser
await browser.close();
})();
In this code snippet, we first launch a new browser instance, navigate to a specific website, find the button element we want to click on using page.$()
, and finally use button.click()
to simulate a click on the button. Finally, we close the browser once we are done with the task.