Blog Details Shape
Automation testing

How to Migrate from Selenium to Playwright

Published:
July 18, 2025
Table of Contents
Join 1,241 readers who are obsessed with testing.
Consult the author or an expert on this topic.

I remember the time when Selenium was first set up. It felt empowering a reliable tool for browser automation. But over time, the shine wore off. I was spending more time fixing broken tests than validating real features.

That’s when I thought of Migrating from Selenium to Playwright and honestly, I wish I had done it sooner. The speed, stability, and built-in smart features just work.

What makes Playwright stand out from Selenium is its clarity. I can avoid watching every test because automation functions properly now. Better context exists, perceptive reports exist, also debugging and tools such as smart test report perceptions run smoother now.

If you're still upon the fence, ask yourself: do your tests accelerate your team or slow them down?

Tools like Playwright paired with AI-powered improvements like automation efficiency boosters, switching isn’t just an upgrade, it’s a competitive edge.

Selenium Architecture

Selenium is an open-source tool used for automating web browsers. It provides a set of libraries for interacting with browsers programmatically. Selenium operates in a client-server architecture where:

  • Selenium WebDriver acts as the client, which communicates with the browser through a browser driver (like ChromeDriver, GeckoDriver for Firefox, etc.).
  • Selenium Server acts as an intermediary between the WebDriver and the browser, sending commands to the browser through the driver.

This architecture relies heavily on the browser’s native automation interfaces, which can be relatively slow and prone to inconsistencies in cross-browser interactions.

Playwright Architecture

Playwright, on the other hand, was developed by Microsoft and is specifically designed for modern web automation. It is faster and more reliable compared to Selenium. Playwright uses a Node.js-based API, which interacts directly with browser automation protocols. The Playwright architecture consists of:

  • Playwright Client: A Node.js library that interacts with browsers.
  • Playwright Browsers: It supports multiple browsers including Chromium, Firefox, and WebKit (Safari), directly interacting with browser engines without needing external drivers.
  • Playwright Inspector: A graphical tool for debugging, which provides visual feedback and insight into the automation process.

Playwright’s direct communication with browsers using the browser’s native DevTools Protocols makes it much faster and more stable than Selenium. It allows for parallel execution, better handling of modern web elements, and features like capturing screenshots and videos of tests.

When should you migrate from Selenium to Playwright?

You know it’s time when your automated tests and test scripts become a liability, not an asset, and you need to consider migrating your scripts to a more reliable framework.

1. Signs Your Selenium Setup Is Outdated

  • You rely on wait() hacks more than assertions
  • Your team avoids adding tests
  • You built custom tools just to understand logs

If your QA feels more like firefighting than quality assurance, it’s time to explore faster,  AI-augmented testing approaches that go beyond fragile selectors and boilerplate code.

2. When It’s Not the Right Time

Don’t switch just because.If your suite is stable, minimal and not blocking delivery, migration may not be urgent. 

Before migrating, consider the programming language used in your test suite, as changing languages can impact collaboration, learning curves, and the structure of your automation processes.

Also, regulated or legacy-heavy systems may need deeper consideration around test governance and ethical AI testing boundaries before jumping in.

3. Is Your Team Ready for Playwright?

Playwright rewards teams ready for speed. If you’ve embraced DevOps, continuous delivery and AI-powered quality, Playwright will feel like a natural fit.

Playwright also enables teams to automate user-like interactions in their tests, closely simulating real user behavior for more accurate web application testing.

If that sounds like your vibe, it's worth exploring how it can reshape your workflows especially in mobile and privacy-focused testing environments.

{{cta-image}}

Differences between Selenium and Playwright

Selenium vs Playwright Comparison
Feature Selenium Playwright
Wait Handling Manual waits often required (WebDriverWait) Built-in auto-wait for elements and actions
Architecture Multi-language, external drivers needed Node-based, comes with bundled browser binaries
Test Speed Slower due to network calls and sync issues Faster due to modern architecture and parallel execution
Cross-Browser Support Supports all major browsers including Internet Explorer Supports modern browsers (Chromium, Firefox, WebKit), no IE
Debugging & Tracing Limited built-in tools, mostly third-party Rich debugging features (trace viewer, screenshots, videos)

Migrate Selenium test to a Playwright test

Let’s see how you can turn your old Selenium code into cleaner, faster Playwright code in both Java and JavaScript. It's easier than you think and way more reliable.

Example 1: Opening a Page and Clicking a Button

Selenium Code (Java)

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
‍
public class SeleniumExample {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
        WebElement button = driver.findElement(By.id("submitButton"));
        button.click();
‍
        driver.quit();
    }
}

Copied!

Playwright Code (Java)

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");
            page.locator("#submitButton").click();
            browser.close();
        }
    }
}

Copied!

Selenium Code (JavaScript)

const { Builder, By } = require('selenium-webdriver');
‍
(async function example() {
    let driver = await new Builder().forBrowser('chrome').build();
    await driver.get('https://example.com');
‍
    let button = await driver.findElement(By.id('submitButton'));
    await button.click();
‍
    await driver.quit();
})();

Copied!

Playwright Code (JavaScript)

const { chromium } = require('playwright');
‍
(async () => {
    const browser = await chromium.launch();
    const page = await browser.newPage();
    await page.goto('https://example.com');
‍
    await page.locator('#submitButton').click();
‍
    await browser.close();
})();

Copied!

Example 2: Filling a Form

Selenium Code (Java)

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
‍
public class SeleniumExample {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
‍
        WebElement inputField = driver.findElement(By.id("username"));
        inputField.sendKeys("testuser");
‍
        driver.quit();
    }
}

Copied!

Playwright Code (Java)

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");
‍
            page.locator("#username").fill("testuser");
‍
            browser.close();
        }
    }
}

Copied!

Selenium Code (JavaScript)

const { Builder, By } = require('selenium-webdriver');
‍
(async function example() {
    let driver = await new Builder().forBrowser('chrome').build();
    await driver.get('https://example.com');
‍
    let inputField = await driver.findElement(By.id('username'));
    await inputField.sendKeys('testuser');
‍
    await driver.quit();
})();

Copied!

Playwright Code (JavaScript)

const { chromium } = require('playwright');
‍
(async () => {
    const browser = await chromium.launch();
    const page = await browser.newPage();
    await page.goto('https://example.com');
‍
    await page.locator('#username').fill('testuser');
‍
    await browser.close();
})();

Copied!

Example 3: Waiting for an Element

Selenium Code (Java)

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
‍
public class SeleniumExample {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
‍
        WebDriverWait wait = new WebDriverWait(driver, 10);
        WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("welcomeMessage")));
        
        driver.quit();
    }
}

Copied!

Playwright Code (Java)

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");
‍
            page.locator("#welcomeMessage").waitFor(new LocatorWaitForOptions().setState(LocatorWaitForState.VISIBLE));
‍
            browser.close();
        }
    }
}

Copied!

Selenium Code (JavaScript)

const { Builder, By, until } = require('selenium-webdriver');
‍
(async function example() {
    let driver = await new Builder().forBrowser('chrome').build();
    await driver.get('https://example.com');
‍
    let element = await driver.wait(until.elementLocated(By.id('welcomeMessage')), 10000);
‍
    await driver.quit();
})()

Copied!

Playwright Code (JavaScript)

const { chromium } = require('playwright');
‍
(async () => {
    const browser = await chromium.launch();
    const page = await browser.newPage();
    await page.goto('https://example.com');
‍
    await page.locator('#welcomeMessage').waitFor({ state: 'visible' });
‍
    await browser.close();
})();

Copied!

Selenium to Playwright API mapping

Selenium vs Playwright Comparison
Action Selenium (JavaScript) Playwright (JavaScript)
Launch Browser let driver = new webdriver.Builder().forBrowser('chrome').build(); const browser = await chromium.launch();
const page = await browser.newPage();
Open URL await driver.get('https://example.com'); await page.goto('https://example.com');
Find Element const el = await driver.findElement(By.id('myId')); const el = page.locator('#myId');
Click Element await el.click(); await el.click();
Type Input Text await el.sendKeys('Hello World'); await el.fill('Hello World');
Wait for Element await driver.wait(until.elementLocated(By.id('myId')), 10000); await page.locator('#myId').waitFor();
Take Screenshot await driver.takeScreenshot().then(img => fs.writeFileSync('screenshot.png', img, 'base64')); await page.screenshot({ path: 'screenshot.png' });
Close Browser await driver.quit(); await browser.close();
Select Dropdown Option await driver.findElement(By.id('dropdown')).sendKeys('Option 1'); await page.selectOption('#dropdown', 'option1');
Get Text from Element const text = await el.getText(); const text = await el.textContent();
Check Element Visibility await el.isDisplayed(); await el.isVisible();
Hover Over Element const actions = driver.actions({ bridge: true });
await actions.move({ origin: el }).perform();
await page.hover('#myId');
Switch to Frame await driver.switchTo().frame(driver.findElement(By.tagName('iframe'))); const frame = page.frame({ name: 'frameName' });
Handle Alert/Popup await driver.switchTo().alert().accept(); page.on('dialog', dialog => dialog.accept());
Upload File await driver.findElement(By.id('upload')).sendKeys('/path/to/file'); await page.setInputFiles('#upload', '/path/to/file');

Steps for Selenium to Playwright migration

1. Set Up Playwright

# Ensure Node.js is installed
node -v
‍
# Install Playwright
npm install -D @playwright/test
npx playwright install

Copied!

2. Create a Basic Playwright Script

// basic-test.js
const { test, expect } = require('@playwright/test');
‍
test('Open Google and search', async ({ page }) => {
  await page.goto('https://www.google.com');
  await page.locator('input[name="q"]').fill('Playwright');
  await page.keyboard.press('Enter');
  await expect(page).toHaveTitle(/Playwright/);
});

Copied!

3. Map Selenium Commands to Playwright

// Selenium to Playwright equivalents
// Selenium: driver.findElement(By.id("username"))
// Playwright:
const username = page.locator('#username');
‍
// Selenium: element.click()
// Playwright:
await username.click();
‍
// Selenium: element.sendKeys("hello")
// Playwright:
await username.fill("hello");
‍
// Selenium: driver.get("https://example.com")
// Playwright:
await page.goto("https://example.com");
‍
// Selenium: driver.quit()
// Playwright:
await browser.close();

Copied!

4. Handle Waits and Asynchrony

// Selenium
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login")));
‍
// Playwright (auto-waits)
await page.locator('#login').click(); // waits automatically for visibility and clickability

Copied!

5. Implement Advanced Features

// Iframe handling in Playwright
const frame = page.frame({ name: 'my-frame' });
await frame.locator('#submit').click();
‍
// File upload
await page.setInputFiles('#upload-input', 'files/resume.pdf');
‍
// Download handling
const [ download ] = await Promise.all([
  page.waitForEvent('download'),
  page.click('text=Download File')
]);
await download.saveAs('./downloadedFile.pdf');

Copied!

6.Run and Debug

# Run the test
npx playwright test basic-test.js
‍
# Run in debug mode with Playwright Inspector
PWDEBUG=1 npx playwright test

Copied!

Waiting for elements: Playwright vs Selenium

Selenium vs Playwright Waiting Strategies
Waiting Strategy Selenium Playwright
Manual wait Thread.sleep(5000) Not needed (anti-pattern in Playwright)
Explicit wait WebDriverWait(driver, 10).until(...) await locator.waitFor();
Implicit wait driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); No need — Playwright auto-waits
Auto-waiting Not supported Default behavior (clicks, fills, navigations, etc.)
AJAX/SPAs Often flaky or inconsistent Built to handle dynamic apps and AJAX-rich pages

How to migrate Selenium to Playwright smoothly

Still dealing with flaky waits and driver errors in Selenium? You’re not alone.

Switching to Playwright is like going from a flip phone to a flagship smartphone, faster, cleaner, and made for modern testing.

Start small: migrate stable login or smoke tests using this,

npx playwright install

Copied!

Use an API mapping to transition smoothly and keep coverage intact. With Playwright’s built-in auto-waiting, parallel execution, and isolated browser contexts, there’s no need for complex Grid setups.

Steps Migration Selenium to Playwright

1.  Create a Migration Plan

Start small  and smart.Begin by migrating one module at a time. Pick stable, high-impact tests like login or search.

For example, a retail team started with their login and search flows critical and run daily.They kept Selenium and Playwright running together for two weeks to validate results. Once confident, they fully switched.

The result? Faster runs, cleaner code, and fewer headaches.

2. Replace Selenium Pain Points

Playwright handles waits automatically, so no more WebDriverWait or time.sleep hacks slowing you down.

Example: A fintech company replaced dozens of sleep and wait conditions in Selenium with Playwright’s auto-wait, cutting test time by 40%.

It also simplifies actions like clicks and form fills shorter, cleaner scripts that just work.

3. Modular Setup

Thinking of cleaning up your messy test setup? 

Playwright makes it easy with a modular structure, split things into folders like tests, fixtures, and configs.

Start small: refactor your login or checkout flows one at a time. Suddenly, it feels future-ready and easier to manage.

Example: A SaaS startup created clear folders for auth, dashboard, and billing. Teams could work in parallel without stepping on each other’s code.

{{cta-image-second}}

Common pitfalls to avoid during Selenium to Playwright migration

Mistake 1: Copy-Pasting Selenium Logic

You don’t move into a smart home and keep flipping light switches manually. Yet many teams copy old Selenium patterns into Playwright.

Things like explicit waits, verbose locators, and over-structured classes only slow you down. Embrace modern testing features built into Playwright instead of dragging legacy logic with you.

Embrace modern testing features built into Playwright instead of dragging legacy logic with you.

Mistake 2: Not Using Playwright’s Auto-Waiting Properly

Playwright’s biggest superpower auto-waiting gets overlooked. Teams still write manual delays out of habit, then wonder why tests flake.

Playwright automatically waits for elements to be ready before interacting, so you can trust Playwright’s auto-waiting for UI readiness; it’s designed to replace your old polling logic and reduce false negatives.

Mistake 3: Ignoring Parallelization Benefits

If you’re still running tests sequentially after switching, you’re missing out on serious speed. 

Playwright’s native parallel execution with browser context isolation gives you the ability to run tests concurrently without race conditions. We used it to cut our CI time nearly in half on Alphabin’s internal platform.

Conclusion

Migrating from Selenium to Playwright isn’t just a framework switch, it’s a shift toward speed, stability and smarter automation. In this blog we broke down setup time, execution speed, auto-waiting, debugging and code clarity to help you see why Playwright is quickly becoming the go-to for modern QA teams.

At Alphabin we’ve streamlined this transition using our in-house platform, TestGenX. It allows teams to design robust tests in minutes, handle dynamic UIs with ease and eliminate repetitive maintenance cycles that slow down delivery.

Paired with TestDino, our intelligent test analysis tool, you get complete visibility into test health real-time failure clustering, flakiness alerts and zero guesswork in debugging. For high-growth teams this combo removes bottlenecks and lets quality keep up with innovation.

FAQs

1. Is Playwright faster than Selenium?

Playwright is in fact faster through automatic waits as well as built-in parallelism. Tests then run faster and less issues fail.

2. Do I need to rewrite all Selenium tests?

No, you don’t need a full rewrite. Many Selenium flows can be adapted with refactoring and minor adjustments to fit Playwright’s syntax.

3. Can I run both in the same CI pipeline?

Yes, you can configure them to run separately within the same pipeline. This helps teams migrate gradually without breaking current test flows.

4. Does Playwright support CI/CD?

Yes, it integrates smoothly with tools like GitHub Actions, Jenkins, and CircleCI. It’s built for automation and works well in modern DevOps setups.

5. Does Playwright support Internet Explorer?

No, Playwright doesn’t support IE as it focuses on modern browsers. You’ll need Selenium for testing legacy apps on Internet Explorer.

Something you should read...

Frequently Asked Questions

FAQ ArrowFAQ Minus Arrow
FAQ ArrowFAQ Minus Arrow
FAQ ArrowFAQ Minus Arrow
FAQ ArrowFAQ Minus Arrow

Discover vulnerabilities in your  app with AlphaScanner 🔒

Try it free!Blog CTA Top ShapeBlog CTA Top Shape
Discover vulnerabilities in your app with AlphaScanner 🔒

About the author

Pratik Patel

Pratik Patel

Pratik Patel is the founder and CEO of Alphabin, an AI-powered Software Testing company.

He has over 10 years of experience in building automation testing teams and leading complex projects, and has worked with startups and Fortune 500 companies to improve QA processes.

At Alphabin, Pratik leads a team that uses AI to revolutionize testing in various industries, including Healthcare, PropTech, E-commerce, Fintech, and Blockchain.

More about the author
Join 1,241 readers who are obsessed with testing.
Consult the author or an expert on this topic.
Pro Tip Image

Pro-tip

Blog Quote Icon

Blog Quote Icon

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Related article:

Still worried about switching from Selenium? we’ve got your backAlready losing time to broken tests? Let’s fix that
Blog Newsletter Image

Don’t miss
our hottest news!

Get exclusive AI-driven testing strategies, automation insights, and QA news.
Thanks!
We'll notify you once development is complete. Stay tuned!
Oops!
Something went wrong while subscribing.