Playwright vs Selenium WebDriver Syntax Comparison by Example

Raw Selenium WebDriver with Ruby Binding is much better.

Zhimin Zhan
9 min readDec 25, 2022


A repost of my daughter’s article with permission. I added a few notes.

Update 2023–01–09: Playwright vs Selenium Speed Comparison

In my intern role early this year, I developed a set of automated test scripts. To be exact, 29 test cases, running reliably on a daily basis. My colleagues and managers were impressed.

I started with Selenium WebDriver with Rspec first. Later, I was told to use Playwright by the department’s test automation guru (of a large telecom company). As a 20-year-old fresh-out-of-Uni intern, of course, I listened. I did the Selenium Ruby version for new test scenarios first (much easier) and then converted it to Playwright. I also set up two build projects in the BuildWise CT server to run both versions daily.

This article will show the syntax difference between Playwright and Selenium, using a simple test case (login test) as an example.

· Comparison with a simple test case
Understand Automated Test Script Tiered Structure
While Real Test Automation is Hard, it is still achievable
Choose a Good Scripting Language
Zhimin’s Notes

Comparison with a simple test case

Raw Selenium (Ruby):

driver.find_element(:id, "username").send_keys("agileway")
driver.find_element(:name, "password").send_keys("testwise")
driver.find_element(:xpath, "//input[@value='Sign in']").click
expect(driver.find_element(:tag_name, "body").text).to include("Signed in")

Playwright (JavaScript):

await driver.fill("#username", "agileway")
await driver.fill("#password", "testwise")
await"input:has-text('Sign in')")
await driver.textContent("body").then(function(body_text) {
assert(body_text.contains("Signed in"))

To me, the Selenium version is better. JS programmers might disagree, read on.

While I am a programmer myself, I have learned (from my father) that scripting automated tests…



Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.