puppeteer button clickl code example

Example 1: run node script pupeeter when button from form clicked

(async () => {
  const browser = await puppeteer.launch({ headless: true })
  const page = await browser.newPage()
  await page.setViewport({ width: 1280, height: 800 })
  await page.goto('https://www.staples.com/Painting-Supplies/cat_CL140420/bww15', { waitUntil: 'networkidle2' })
  await page.click('button.add-to-cart-btn.addToCart')
  await page.waitForSelector('h4.cart-items-header')
  await page.screenshot({ path: screenshot })
  await browser.close()
  console.log('See screen shot: ' + screenshot)
 })()

Example 2: run node script pupeeter when button from form clicked

(async () => {
 const browser = await puppeteer.launch({ headless: true })
 const page = await browser.newPage()
 await page.goto('https://github.com/login')
 await page.type('#login_field', process.env.GITHUB_USER)
 await page.type('#password', process.env.GITHUB_PWD)
 await page.click('[name="commit"]')
 await page.waitForNavigation()
 await page.screenshot({ path: screenshot })
 browser.close()
 console.log('See screenshot: ' + screenshot)
})()