Pyppeteer Tutorial: Guide to Puppeteer in Python (with Examples)
On This Page What is Pyppeteer?Use cases of PyppeteerJanuary 22, 2026 · 11 min read · Testing Guide
is the most popular mechanization testing tool by Google. However, it indorse only JavaScript programming language. Many Python enthusiasts and community contributors group to support Python for Puppeteer. Pypeeteer is a port of Puppeteer and it mimics the Puppeteer API by apply the Python programming language. What is Pyppeteer? Pyppeteeris an unofficial Python porthole of Puppeteer, a Node.js library, that automates Chromium-based browser through the DevTools Protocol. Why Use Puppeteer? This usher explains what Pyppeteer is, its usage, how it differs from Puppeteer, stake practices and more. Pyppeteer is a Python version of the Puppeteer mechanisation tool. It helps to automatise the web covering apply the Python lyric. It continues to keep the core functionality like to Puppeteer. Pyppeteer supports Chromium and Chrome browsers for. It is an open-source package distributed under MIT license. Read More: Here are some of the use cases of Pyppeteer: 1. Web Scraping Dynamic Content 2. Automated Form Submission 3. PDF Generation from Web Pages 4. and Monitoring 5. Website Screenshot Automation 6. Social Media or SEO Bot Tasks 7. Emulating Devices and Networks 8. Capturing Performance Metrics 9. Captcha Pre-checks (Non-breaking Only) 10. Browser Fingerprint Emulation Read More: Fundamentally, both are built on the same architecture. However, Pyppeteer is a ported version of Puppeteer JavaScript as there are programming-level limitation few things may change. A few pyppeteer examples are listed below: Puppeteer uses an target for passing parameters to functions. Pyppeteer functions accept both dictionary and keyword arguments for options Example: Puppeteer JavaScript uses the$for the element picker. However, in Python,$is not a valid identifier, instead of$python expend J as a tachygraphy operator as name below: Puppeteer & # 8217; s version of JavaScript evaluate () lead a JavaScript map or a string representation of a JavaScript expression. However, Pyppeteer lead a string representation of JavaScript or a function Example: You experience discussed Pyppeteer and Puppeteer deviation understand the usage with the Pyppeteer example: Note:Pyppeteer project is no longer actively maintained. The late version of Pyppeteer doesn ’ t employment smoothly, it is not recommended to use Pyppeteer rather as per the documentation it propose using Playwright Python which is well-maintained and more similar to Pyppeteer. Discuss installing and setting up a Pyppeteer using Python. Pre-requisites to install Pyppeteer Install Pyppeteer Once the initiation is successful you are full to part the automation. Read More: It is significant to cognise about the action that can be perform using the Pyppeteer. If you are already familiar with Puppeteer the learning curve will be very minimal. Understand the different action in Pyppeteer To launch the browser you involve to create the browser instance first. SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. This can be used to create the browser instance or context. Using the browser object you can create as many Page as possible Pyppeteer Example: In the above codification, a browser representative is create foremost and so name a newPage () method to get the new page. Once a new page is created, you can perform action like sail to the URL (example:https: //www.google.com), etc. Read More: Pyppeteer is more flexible and customizable, You can specify the browser executable to launch the browser. For example, if you have already installed a specific variation of Chrome you can pass the path to thelaunch()function as mentioned below Consider you want to search for something on the page, you can use the page.type () method to execute the action Example: In the above method, # mySearch is the locater and BrowserStack is the Search text Pyppeteer get clicking buttons very simple,page.click ()method can be used to perform the click activeness.page.click ()method accepts one parameter that is the locator, the locator can be any valid css locator. Example: Pyppeteer let you to print or save the webpage as PDF, rather of taking a screenshot you can save the unhurt page in PDF format. Page.pdf () function can be used for this function. Example: Pyppeteer follows a different access to switching the tabs. As mentioned earlier you can create as many as pages you want once you get the browser illustration. Understand with an example: In the above example, you have make two pages videlicet page1 and page2, page1 represents the first page and page2 represents the second page. You can just use page 1 or foliate 2 to perform the activity. Example: Clicking on the hunt button on the 2nd page Pyppeteer provides the capableness to contend the cookies. You can Set, Print, and Delete the cookies. Below are the available methods to manage cookies Example: Read More: IFrames are a legacy technique to dissever the page, still, Pyppeteer support iFrame actions. For example, if you want to perform a click action on a specific element on the iFrame you can postdate the below access Example: Alerts and pop-ups are native to the operating system. These can be handled using theasyncio()functionality. Below are example of handle the browser popups and alarum messages Example: Handle Confirm Dialog Box Example: Handle Dismiss Dialog Box Similarly, you can care different types of Dialogs Dynamic web elements are a new standard of modern web applications. For example, when you navigate to the page it loads only contents or elements for the current viewport. As you scroll down additional substance are lend. In such scenario, if you navigate to the web page and perform an activity it throws the exception with the error factor not found. One of the answer for this is to scroll down until webpage elements are visible. This scenario can be handled in Pyppeteer utilize thescrollIntoView () function. Example: Once element is found perform the action Read More: Pyppeteer doesn & # 8217; t support parallel execution. That means you can not run multiple tryout at a single point of clip however this can be achieved using the third-party plugin calledpytest-parallel. Once you install pytest-parallel you can use the following command to run the test in analog Pyppeteer Python is a good combination for scraping web page. Web scrape helps to perform research in the industry, especially in the retail segment. Competitors make an analysis of particular products, their SKUs, pricing and discounts, etc. Pyppeteer can be used for web scraping. Below is a simple example of web scraping. Example: As discourse in the above subdivision, Pyppeteer is a fork of Puppeteer JavaScript. The browser support is the same as the Puppeteer. Puppeteer is intend to execute testing in browser just. It doesn & # 8217; t endorse any early browser. Though it has experimental support for Firefox it is not recommended to use. Due to these limitations, can not be reach utilise Pyppeteer. However, the best alternative is to use Python Playwright which supports many different browsers without any hassle. Read More: Here are some of the best practices for expend Pyppeteer: 1. Use waitForSelector ()Instead of Fixed Timeouts 2. Run in Headless Mode for Performance 3. Close Browser Instances Properly 4. Isolate Browser Contexts:Use browser.createIncognitoBrowserContext ()for independent session (good for multi-user mechanization or try). 5. Throttle Requests for Scraping:Respect server load; add random delay between requests to mimic human behavior. 6. Intercept and Block Unnecessary Requests:Use page.setRequestInterception (true)to embarrass images, typeface, and ads for faster performance. 7. Use Page Evaluation Wisely:Prefer page. $ eval () and page.evaluate ()for in-page computations rather than sending raw information back to Python. 8. Handle Exceptions Gracefully:Use try-catchblock and meaningful error messages to make debug easier. 9. Leverage Async/Await Correctly:Ensure all async operations are awaited properly to deflect race weather or irregular behaviors. 10. Keep Dependencies Updated:Pyppeteer depends on Chromium and internal protocols—stay updated to avoid break due to browser protocol changes. Pyppeteer is in the care phase and it is no longer actively maintained. As mentioned before, the latest version of the Pyppeteer doesn & # 8217; t grant to download the latest browsers. Since Pyppeteer stopped fighting development there is not much support for the cloud execution. Even though this can be reach through some hacks, constancy, and dependableness can not be guaranteed. Note:However, If you have a cloud execution requirement you can transmigrate your task to Puppeteer and JavaScript. If you feel programming language is a barrier you can consider swap to Playwright Python. supports both Puppeteer JavaScript and Playwright Python seamlessly without any hassle. You can and screen your covering on 3500+ real device to test on the cloud. Puppeteer is the most popular instrument for test automation, however, it lacks programming language support early than JavaScript, to whelm this challenge Pyppeteer is a fork from Puppeteer and written wrapper to support Python language. Due to recent developments, the Pyppeteer project is not actively maintained. When it comes to automation Cross browser examination, Cloud trial execution, and parallel execution are the most crucial thing to attain the ROI. However, Pyppeteer lacks all three all-important feature. Unless you test your covering on multiple twist and browser combinations you can not predict the behavior of the application in production and it is always riskier. As recommended by the Pyppeteer squad consider switch to Playwright Python which enables all important features without any fuss. Additionally, supports Playwright seamlessly, this helps to attain good ROI from automation and also help to release your code with confidence. On This Page # Ask-and-Contributeabout this subject with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Pyppeteer Tutorial: Guide to Puppeteer in Python (with Examples)
Overview
What is Pyppeteer?
Use cases of Pyppeteer
Differences between Puppeteer and Pyppeteer
browser = await launch ({'headless ': True}) browser = await launch (headless=True)Puppeteer Pyppeteer Pyppeteer stenography Page.$() Page.querySelector () Page.J() Page.$$() Page.querySelectorAll () Page.JJ() Page.$x() Page.xpath () Page.Jx() content = await page.evaluate ('document.body.textContent ', force_expr=True)How to set up Pyppeteer?
pip install Pyppeteer
How to perform various Actions on Pyppeteer
Launching the browser with Pyppeteer
browser = await launch ()
import asyncio from pyppeteer import launching async def scraper (): browser =await launching ({`` headless '': False}) page = await browser.newPage () await page.goto ('https: //www.google.com/ ') expect browser.close () asyncio.run (scraper ())Opening specific versions of Chrome/Chromium browser with Pyppeteer
browser = await launching (headless=False, executablePath= ' C: \\Program Files\\Google\\Chrome\Application\\chrome.exe ')
Typing the Test on the web page
page.type (`` # mySearch '', `` Browserstack '');
Clicking the Button on the Webpage
page.click (' # mybtn ');Printing PDF files with Pyppeteer
await page.pdf ({'path ': 'python_print.pdf '})Switching Tabs with Pyppeteer
browser =await launch ({`` headless '': False}) page1 = await browser.newPage () page2 = await browser.newPage () expect page1.goto ('https: //www.google.com/ ') await page2.goto ('https: //www.browserstack.com/ ');await page2.click (' # browserstackSearchButtton ')Managing Cookies with Pyppeteer
await page.cookies (): Get all the available cookies await page.setCookie (... cookies): Set the Cookie await page.deleteCookie (... cookieNames): Delete the cookie
Handling iFrames with Pyppeteer
iframe_element = await page.querySelector (iframe_1) iframe = await element.contentFrame () await iframe.querySelector (iframe_button) .click ()
Handling Alerts and Pop-ups with Pyppeteer
page.on ('dialog ', handle_confirm _dialog_box) def handle_confirm _dialog_box (dialogue): asyncio.ensure_future (dialog.accept (test_message))page.on ('dialog ', handle_dismiss_dialog_box) def handle_dismiss_dialog_box (dialog): asyncio.ensure_future (dialog.dismiss ())Handling Dynamic Content with Pyppeteer
Scroll until the element is seeable async def scroll_to_element (page, picker): await page.evaluateHandle ('' 'async (chooser) = & gt; {const element = document.querySelector (selector); if (element) {element.scrollIntoView ();}} '' ', selector) return selectorelem_button_footer = await scroll_to_element (page, button_footer) await page.click (elem_button_footer)
Parallel Execution with Pyppeteer
Web Scraping with Pyppeteer
async def scrape_it (page, url) - & gt; leaning: page.goto ('https: //someretailwebsite.com ') rows = await page.querySelectorAll (' # product_cards ') scraping_data_arr = [] for row in rows: name = await row.querySelector (' p.name ') damage = await row.querySelector ('div.price-value ') nameText = await page.evaluate (' (element) = & gt; element.textContent ', name) priceValue = await page.evaluate (' (element) = & gt; element.textContent ', price) scraping_data_dict = {'product name ': nameText, 'product price ': priceValue} scraping_data_arr.append (scraping_data_dict) return scraping_data_arrCross Browser Testing with Pyppeteer
Good Practices for using Pyppeteer
How to run Pyppeteer Tests on Real Devices with BrowserStack Automate
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously