- Puppeteer - Discussion
- Puppeteer - Useful Resources
- Puppeteer - Quick Guide
- Puppeteer - Capture Screenshot
- Puppeteer - Synchronization
- Puppeteer - Disable JavaScript
- Puppeteer - Device Emulation
- Puppeteer - Getting Element Attribute
- Puppeteer - Getting Element Text
- Puppeteer - Keyboard Simulation
- Puppeteer - Handling Frames
- Handling Edit Boxes & Checkboxes
- Puppeteer - Handling Links/Button
- Puppeteer - Attribute Selector
- Puppeteer - Id Selector
- Name Selector & Class Name Selector
- Puppeteer - Type Selector
- Puppeteer - Xpath Axes
- Puppeteer - Relative Xpath
- Puppeteer - Absolute Xpath
- Puppeteer - Xpath Grouping
- Puppeteer - Xpath Attributes
- Puppeteer - Xpath Functions
- Puppeteer - Locators
- Puppeteer - Handling Drop-downs
- Puppeteer - Handling Confirm Alerts
- Puppeteer - Chrome
- Puppeteer - Firefox
- Puppeteer - Basic Commands
- Puppeteer - Handling Tabs
- Puppeteer - Browser Operations
- Comparison Between Puppeteer & Cypress
- Comparison Between Puppeteer & Protractor
- Comparison Between Puppeteer & Selenium
- Puppeteer - Non Headless Execution
- Puppeteer - Basic Test
- Puppeteer - Installation
- Puppeteer VS Code Configuration
- Puppeteer - NodeJS Installation
- Puppeteer - Usage of Google
- Puppeteer - Element Handling
- Puppeteer - Introduction
- Puppeteer - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Puppeteer - Basic Commands
Some of the basic commands of Puppeteer are psted below −
title()
This command is used to obtain the title of the present page.
Syntax
The syntax is as follows −
await page.title()
url()
This command is used to obtain the URL of the apppcation currently launched in the browser.
Syntax
The syntax is as follows −
await page.url()
content()
This command is used to obtain the page source code.
Syntax
The syntax is as follows −
await page.content()
To begin, follow Steps 1 to 2 from the Chapter of Basic Test on Puppeteer which are as follows −
Step 1 − Create a new file within the directory where the node_modules folder is created (location where the Puppeteer and Puppeteer core have been installed).
The details on Puppeteer installation is discussed in the Chapter of Puppeteer Installation.
Right-cpck on the folder where the node_modules folder is created, then cpck on the New file button.
Step 2 − Enter a filename, say testcase1.js.
Step 3 − Add the below code within the testcase1.js file created.
//adding Puppeteer pbrary const pt = require( puppeteer ); pt.launch().then(async browser => { //browser new page const p = await browser.newPage(); //set viewpoint of browser page await p.setViewport({ width: 1000, height: 500 }) //launch URL await p.goto( https://www.tutorialspoint.com/questions/index.php ) //obtain page title console.log("Page title: " + await p.title()) //obtain URL console.log("Url: " + await p.url()) //browser close await browser.close() })
Step 4 − Execute the code with the command given below −
node <filename>
So in our example, we shall run the following command −
node testcase1.js
After the command has been successfully executed, the page title - The Best Technical Questions and Answers gets printed in the console. Also, the URL -
gets printed in the console. The execution has happened in the headless mode. Advertisements