Move JavaScript Selenium WebDriver tests to Playwright Test: findElement, waits, Select, alerts, windows, cookies and executeScript mapped to Playwright code, with a checklist, gotchas and live numbers for both tools.
Selenium (live data): 34,606 GitHub stars. 6,501,858 weekly PyPI downloads (selenium), -3% over 4 weeks. 5 GitHub releases in the last 60 days, latest v4.54.0. last GitHub activity 2026-11-23
Playwright (live data): 100,863 GitHub stars. 138,786,046 weekly npm downloads (@playwright/test), +68% over 4 weeks. 4 GitHub releases in the last 60 days, latest v1.65.1. last GitHub activity 2026-11-22
Start a browser: Selenium WebDriver (JavaScript): const driver = await new Builder() .forBrowser(Browser.CHROME).build() → Playwright Test: test('title', async ({ page }) => { // page comes from the runner }) // browser per project: use: { ...devices['Desktop Chrome'] }
End the session: Selenium WebDriver (JavaScript): await driver.quit() → Playwright Test: // nothing: the runner closes the page and context
Navigate: Selenium WebDriver (JavaScript): await driver.get('https://www.selenium.dev/selenium/web/web-form.html') → Playwright Test: await page.goto('https://www.selenium.dev/selenium/web/web-form.html')
Check the title: Selenium WebDriver (JavaScript): let title = await driver.getTitle() assert.equal('Web form', title) → Playwright Test: await expect(page).toHaveTitle('Web form')
Find an element: Selenium WebDriver (JavaScript): await driver.findElement(By.name('my-text')) await driver.findElement(By.css('button')) await driver.findElement(By.id('message')) → Playwright Test: page.locator('[name="my-text"]') page.locator('button') page.locator('#message') (Playwright recommends getByRole, getByLabel and getByTestId over CSS and XPath. Locators are strict: an action throws if more than one element matches.)
Type and click: Selenium WebDriver (JavaScript): await textBox.sendKeys('Selenium') await submitButton.click() → Playwright Test: await page.locator('[name="my-text"]').fill('Selenium') await page.locator('button').click() (fill sets the value in one go. Use pressSequentially only when the page handles each key press.)
Read and assert text: Selenium WebDriver (JavaScript): let value = await message.getText() assert.equal('Received!', value) → Playwright Test: await expect(page.locator('#message')).toHaveText('Received!') (The Playwright assertion retries until it passes or times out (5 s by default).)
Implicit wait: Selenium WebDriver (JavaScript): await driver.manage().setTimeouts({ implicit: 500 }) → Playwright Test: // none: actions wait until the element is visible, // stable, enabled and receives events
Explicit wait: Selenium WebDriver (JavaScript): await driver.wait(until.elementIsVisible(revealed), 2000) await driver.wait(until.elementTextIs(message, 'Received!'), 2000) → Playwright Test: await expect(page.locator('#revealed')).toBeVisible() await expect(page.locator('#message')).toHaveText('Received!')
Select a dropdown option: Selenium WebDriver (JavaScript): const select = new Select(selectElement) await select.selectByVisibleText('Four') await select.selectByValue('two') → Playwright Test: const select = page.locator('select[name="selectomatic"]') await select.selectOption({ label: 'Four' }) await select.selectOption('two')
Alerts and confirms: Selenium WebDriver (JavaScript): await driver.wait(until.alertIsPresent()) let alert = await driver.switchTo().alert() await alert.accept() → Playwright Test: page.on('dialog', dialog => dialog.accept()) await page.getByRole('button').click() (Register the handler before the click. Without a listener Playwright dismisses every dialog.)
New tab or window: Selenium WebDriver (JavaScript): const handles = await driver.getAllWindowHandles() await driver.switchTo().window(handles[1]) → Playwright Test: const pagePromise = context.waitForEvent('page') await page.getByText('open new tab').click() const newPage = await pagePromise (No switching: each tab is its own page object you keep using.)
Run JavaScript in the page: Selenium WebDriver (JavaScript): await driver.executeScript('return arguments[0].innerText', header) → Playwright Test: const text = await page.locator('h1').evaluate(el => el.innerText) // whole page: await page.evaluate(() => document.location.href) (Pass values in as the second argument of evaluate; the callback runs in the browser, not in your test.)
Screenshot: Selenium WebDriver (JavaScript): let encodedString = await driver.takeScreenshot() // base64 string → Playwright Test: await page.screenshot({ path: 'example.png' })
Cookies: Selenium WebDriver (JavaScript): await driver.manage().addCookie({ name: 'key', value: 'value' }) await driver.manage().getCookies() await driver.manage().deleteAllCookies() → Playwright Test: await context.addCookies([{ name: 'key', value: 'value', url: 'https://example.com' }]) await context.cookies() await context.clearCookies() (Selenium sets cookies on the current page's domain. Playwright needs url, or domain and path, on each cookie.)
Run in parallel: Selenium WebDriver (JavaScript): // your runner (e.g. Mocha) or a Selenium Grid: new Builder().usingServer(gridUrl) → Playwright Test: npx playwright test --workers 4 npx playwright test --shard=1/3 (Playwright runs test files in parallel workers by default.)
Checked against: selenium-webdriver 4.52.0, @playwright/test 1.65.0 (npm registry, 2026-11-10)