![]() ![]() To run the code, open a terminal window and navigate to project directory and type following command node screenshot.jsĪfter the script is finished you should see screenshot in current working directory named google. To install puppeteer package as project dependency type following command and press enter npm install installation, the package.json should look similar to following ) We will be using puppeteer version 5.0.0 as a dependency. Puppeteer comes pre-installed with a recent version of Chromium. Navigate to the desired directory and run below command to create a fresh project npm init -y Prerequisite Node 10.18.1+ Create a new project In this tutorial, we are going to see how we can take a screenshot of a page using puppeteer. Puppeteer can be used to interact with the webpage as a normal user would over the DevTools Protocol. By default, puppeteer runs in headless mode. Puppeteer not only provides the capability to take a screenshot but also provides options on how the screenshot should be. Puppeteer can be configured to run in headless and GUI mode. We can capture a screenshot of the webpage using screenshot () function present in Puppeteer. After the element is ready, you need to find it (select it) and then call the screenshot() method. Otherwise, you can miss it and take a screenshot of nothing. This will create a file called package.json inside the directory. Go into the directory and run the command: npm init Hit enter for each question asked. Puppeteer is the NodeJs library that provides API to automate Chrome or Chromium browsers. It is essential to wait until the selector is ready and rendered. Generating Screenshots with Puppeteer Now that we have node.js installed, let’s create a directory called uitesting and open the command prompt or terminal. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |