Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to click on button using Puppeteer?

Link: http://quotes.toscrape.com/

Click on the above link and scroll to the bottom. I don’t know how to click on the Next button.

My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

await page.click(".pager > .next > a")

The above code is not working.

I want to know, how to click on this button.

>Solution :

I use below code and can click Next button. The keypoint here is to use waitForSelector to make sure the element you want is available.

import puppeteer from 'puppeteer';

(async () => {
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();

  await page.goto('http://quotes.toscrape.com/');

  // Set screen size
  await page.setViewport({width: 1080, height: 1024});

  // Wait and click on first result
  const searchResultSelector = '.next a';
  await page.waitForSelector(searchResultSelector);
  await page.click(searchResultSelector);

  // await browser.close();
})();

refs from doc: https://pptr.dev/#example

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading