Table of contents

What programming languages does Playwright support?

Playwright, Microsoft's modern browser automation library, officially supports five programming languages with fully-featured, native APIs:

Supported Languages

  1. JavaScript (Node.js)
  2. TypeScript (Node.js)
  3. Python
  4. C# (.NET)
  5. Java

Language-Specific Installation & Usage

JavaScript/TypeScript

Installation:

npm install playwright
# Install browsers
npx playwright install

JavaScript Example:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');

  // Interact with the page
  await page.click('button');
  const title = await page.title();
  console.log(title);

  await browser.close();
})();

TypeScript Example:

import { chromium, Browser, Page } from 'playwright';

(async (): Promise<void> => {
  const browser: Browser = await chromium.launch();
  const page: Page = await browser.newPage();
  await page.goto('https://example.com');

  const title: string = await page.title();
  console.log(`Page title: ${title}`);

  await browser.close();
})();

Python

Installation:

pip install playwright
# Install browsers
playwright install

Async API Example:

import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        await page.goto('https://example.com')

        title = await page.title()
        print(f"Page title: {title}")

        await browser.close()

asyncio.run(main())

Sync API Example:

from playwright.sync_api import sync_playwright

def main():
    with sync_playwright() as p:
        browser = p.chromium.launch()
        page = browser.new_page()
        page.goto('https://example.com')

        title = page.title()
        print(f"Page title: {title}")

        browser.close()

if __name__ == "__main__":
    main()

C# (.NET)

Installation:

dotnet add package Microsoft.Playwright
# Build to download browsers
dotnet build
# Install browsers
pwsh bin/Debug/net6.0/playwright.ps1 install

Example:

using Microsoft.Playwright;

class Program
{
    public static async Task Main()
    {
        using var playwright = await Playwright.CreateAsync();
        await using var browser = await playwright.Chromium.LaunchAsync();
        var page = await browser.NewPageAsync();

        await page.GotoAsync("https://example.com");
        var title = await page.TitleAsync();
        Console.WriteLine($"Page title: {title}");

        await browser.CloseAsync();
    }
}

Java

Maven Installation (pom.xml):

<dependency>
  <groupId>com.microsoft.playwright</groupId>
  <artifactId>playwright</artifactId>
  <version>1.40.0</version>
</dependency>

Gradle Installation:

implementation 'com.microsoft.playwright:playwright:1.40.0'

Example:

import com.microsoft.playwright.*;

public class PlaywrightExample {
    public static void main(String[] args) {
        try (Playwright playwright = Playwright.create()) {
            Browser browser = playwright.chromium().launch();
            Page page = browser.newPage();

            page.navigate("https://example.com");
            String title = page.title();
            System.out.println("Page title: " + title);

            browser.close();
        }
    }
}

Key Features Across All Languages

  • Cross-browser support: Chromium, Firefox, and WebKit
  • Auto-wait functionality: Built-in smart waiting for elements
  • Mobile emulation: Device-specific testing capabilities
  • Network interception: Mock and modify network requests
  • Screenshots and videos: Visual testing and debugging
  • Parallel execution: Run tests concurrently for faster execution

Language-Specific Considerations

| Language | Test Framework Integration | Async Support | Community | |----------|---------------------------|---------------|-----------| | JavaScript/TypeScript | Jest, Mocha, Playwright Test | Native async/await | Largest | | Python | pytest, unittest | Both sync and async APIs | Strong | | C# | NUnit, xUnit, MSTest | async/await | Growing | | Java | JUnit, TestNG | CompletableFuture | Established |

Each language binding is maintained by the Playwright team, ensuring feature parity and consistent updates across all supported languages.

Try WebScraping.AI for Your Web Scraping Needs

Looking for a powerful web scraping solution? WebScraping.AI provides an LLM-powered API that combines Chromium JavaScript rendering with rotating proxies for reliable data extraction.

Key Features:

  • AI-powered extraction: Ask questions about web pages or extract structured data fields
  • JavaScript rendering: Full Chromium browser support for dynamic content
  • Rotating proxies: Datacenter and residential proxies from multiple countries
  • Easy integration: Simple REST API with SDKs for Python, Ruby, PHP, and more
  • Reliable & scalable: Built for developers who need consistent results

Getting Started:

Get page content with AI analysis:

curl "https://api.webscraping.ai/ai/question?url=https://example.com&question=What is the main topic?&api_key=YOUR_API_KEY"

Extract structured data:

curl "https://api.webscraping.ai/ai/fields?url=https://example.com&fields[title]=Page title&fields[price]=Product price&api_key=YOUR_API_KEY"

Try in request builder

Related Questions

Get Started Now

WebScraping.AI provides rotating proxies, Chromium rendering and built-in HTML parser for web scraping
Icon