Skip to content

playwright

11,134 5 38 Apache-2.0
1.45.0 (3 Jul 2024) Feb 24 2021 3.2 million (month)

playwright is a Python package that allows developers to automate web browsers for end-to-end testing, web scraping, and web performance analysis. It is built on top of WebKit, Mozilla's Gecko, and Microsoft's EdgeHTML, and it is designed to be fast, reliable, and easy to use.

playwright is similar to Selenium, but it provides a more modern and powerful API, with features such as automatic waiting for elements, automatic retries, and built-in support for browser contexts, which allow you to open multiple pages in a single browser instance.

Playwright also provides an asynchronous client which makes scaling playwright-powered web scrapers easier than alternatives (like Selenium)

Example Use


from playwright import sync_playwright

# Start Playwright
with sync_playwright() as playwright:
    # Launch a browser instance
    browser = playwright.chromium.launch()
    # Open a new context (tab)
    context = browser.new_context()
    # Create a new page in the context
    page = context.new_page()

    # Navigate to a website
    page.goto("https://www.example.com")

    # Find an element by its id
    element = page.get_by_id("example-id")

    # Interact with the element
    element.click()

    # Fill an input form
    page.get_by_name("example-name").fill("example text")

    # Find and click a button
    page.get_by_xpath("//button[text()='Search']").click()

    # Wait for the page to load
    page.wait_for_selector("#results")

    # Get the page title
    print(page.title)

    # Close the browser
    browser.close()

Alternatives / Similar


29,780 4.22.0 (24 days ago) Apr 25 2008 compare
9,064 3.5.5 (4 months ago) Sep 04 2020 compare
1,823 0.4.0 (5 months ago) Dec 28 2012 compare
411 1.9.3.1 (a month ago) Jul 22 2022 compare
4,039 3.5 (4 years ago) Apr 25 2014 compare

Other Languages

62,856 1.44.1 (a month ago) Jan 23 2015 compare
10,591 chromedp (11 months ago) Aug 15 2019 compare
2,907 v2.1.1 (7 months ago) Jul 17 2018 compare
Was this page helpful?