Skip to content

ARUSHIGULBHILE/playwright-python

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

🎭 Playwright for Python

PyPI version Anaconda version Join Discord

Playwright is a powerful Python library to automate Chromium, Firefox and WebKit browsers with a single API. Playwright delivers automation that is ever-green, capable, reliable and fast. See how Playwright is better.

🌟 Key Features

  • Cross-browser: Automate Chromium, Firefox, and WebKit with the same API
  • Cross-platform: Works on Windows, macOS, and Linux
  • Cross-language: Same API available in Python, JavaScript, .NET, and Java
  • Auto-waiting: Automatically waits for elements to be ready
  • Mobile emulation: Test responsive web apps with mobile device simulation
  • Network interception: Capture and modify network requests
  • Reliable selectors: Built-in support for text, CSS, XPath, and React selectors

πŸš€ Quick Start

Installation

# Install Playwright
pip install playwright

# Install browser binaries (Chrome, Firefox, WebKit)
playwright install

Your First Script

Create a file example.py:

from playwright.sync_api import sync_playwright

def main():
    with sync_playwright() as p:
        # Launch browser
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()
        page.goto('https://playwright.dev')
        page.screenshot(path='example.png')
        print(f"Page title: {page.title()}")
        browser.close()

if __name__ == "__main__":
    main()

Run your script:

python example.py

πŸ“š Examples

Sync API

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    for browser_type in [p.chromium, p.firefox, p.webkit]:
        browser = browser_type.launch()
        page = browser.new_page()
        page.goto('http://playwright.dev')
        page.screenshot(path=f'example-{browser_type.name}.png')
        print(f"Screenshot saved: example-{browser_type.name}.png")
        browser.close()

Async API

import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        for browser_type in [p.chromium, p.firefox, p.webkit]:
            browser = await browser_type.launch()
            page = await browser.new_page()
            await page.goto('http://playwright.dev')
            await page.screenshot(path=f'example-{browser_type.name}.png')
            print(f"Screenshot saved: example-{browser_type.name}.png")
            await browser.close()

asyncio.run(main())

πŸ› οΈ Installation Guide

Prerequisites

  • Python 3.7 or higher
  • pip package manager
  • Node.js 14 or higher

Step-by-Step Setup

  1. Create virtual environment (recommended):

    python -m venv playwright-env
    source playwright-env/bin/activate
  2. Install Playwright:

    pip install playwright
  3. Install browsers:

    playwright install

Installation Options

  • Specific browser:

    playwright install chromium
    playwright install firefox
  • With conda:

    conda install -c conda-forge playwright

🌐 Supported Browsers

Browser Linux macOS Windows
Chromium βœ… βœ… βœ…
WebKit βœ… βœ… βœ…
Firefox βœ… βœ… βœ…

❓ Troubleshooting

"playwright: command not found"

  • Use: python -m playwright instead of playwright

Browser installation fails

  • Check internet connection
  • Try: playwright install --force

Permission errors

  • Use: sudo playwright install

πŸ“– Learning Resources

🌍 Other Languages

🀝 Contributing

We welcome contributions from the community! Whether you're fixing bugs, adding new features, or improving documentation, your help is appreciated.

How to Contribute

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Commit your changes: git commit -m 'Add amazing feature'
  5. Push to the branch: git push origin feature/amazing-feature
  6. Open a Pull Request

Contribution Guidelines

  • Follow the existing code style
  • Add tests for new functionality
  • Update documentation for changes
  • Ensure all tests pass
  • Be respectful and constructive in discussions

Getting Help


Happy testing! 🎭

About

Python version of the Playwright testing and automation library.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.1%
  • Other 0.9%