Chrome Test Automation: Running and Debugging Selenium WebDriver Scripts

Quality assurance is а crucial aspect of software development, ensuring delivered products meet expectations. With Google Chrome commanding а dominating market share among web browsers, having robust test automation in place for Chrome is imperative. This is where automation testing tools like Selenium enter the arena, facilitating reliable automation testing across browsers.
However, simply running Selenium scripts for Chrome browser testing has some limitations. Debugging script issues, handling asynchronous calls, and test flakiness can hinder productivity. There are ways to optimize the Chrome testing approach using Selenium to accelerate the quality assurance processes.
Understanding ChromeDriver for Selenium test automation
At the heart of Selenium test automation for Google Chrome is the ChromeDriver. It essentially works as а connector between the Selenium scripts and Chrome browser, enabling commands executed in code to be passed to the browser and performed accordingly.
The ChromeDriver gets initialized at the start of test execution through simple syntax:
WebDriver driver = new ChromeDriver();
This launches а new instance of the Chrome browser that can then be programmatically controlled during testing.
Key capabilities offered by ChromeDriver include:
- Launching Chrome with various configuration options:headless mode, mobile emulation, performance logging etc.
- Executing tests across versions of Chrome browser through automatic updates
- Support for latest web standards like CSS, HTML5, JavaScript etc.
- Handling of popup windows and alerts triggered during testing
- Console log access for debugging and analysis
So ChromeDriver opens up immense test automation possibilities with Selenium, bolstering the entire quality assurance process.
Setting Up Selenium with Chrome
Before running or debugging scripts, you need to set up your environment. Here’s what you’ll need:
- Python: Install it from python.org.
- Selenium: Install it with pip install selenium in your terminal or command prompt.
- ChromeDriver: Download it from chromedriver.chromium.org (match your Chrome version), and add it to your system PATH or specify its location in your script.
- Chrome Browser: Ensure Chrome is installed and updated.
Basic Example
Here’s а simple script to open Chrome, visit а website, and print its title:
from selenium import webdriver
import time
# Set up Chrome WebDriver
driver = webdriver.Chrome()
# Open а website
driver.get(“https://www.example.com”)
# Print the page title
print(“Page title:”, driver.title)
# Wait to see the result
time.sleep(2)
# Close the browser
driver.quit()
Run this in your terminal with python script_name.py. If it works, you’ll see the title of “example.com” printed. If not, we’ll debug it later—let’s build on this first.
Running Chrome Tests with Selenium
Running tests means executing scripts that perform actions and check results. Let’s create а more realistic example: logging into а demo site and verifying success.
Example: Login Test
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
# Start Chrome
driver = webdriver.Chrome()
# Go to а demo login page
driver.get(“https://the-internet.herokuapp.com/login”)
# Find and fill the username field
username = driver.find_element(By.ID, “username”)
username.send_keys(“tomsmith”)
# Find and fill the password field
password = driver.find_element(By.ID, “password”)
password.send_keys(“SuperSecretPassword!”)
# Click the login button
login_button = driver.find_element(By.CLASS_NAME, “radius”)
login_button.click()
# Check if login worked (look for success message)
success_message = driver.find_element(By.ID, “flash”)
print(“Result:”, success_message.text)
# Wait and close
time.sleep(2)
driver.quit()
What’s Happening?
- Opens Chrome and navigates to а test site.
- Finds elements by ID or class and interacts with them.
- Verifies the result by checking а message.
This runs fine on а simple site, but real-world apps can be complex—slow pages, dynamic elements, or errors. Let’s improve it and then learn to debug.
Running in Headless Mode
For faster execution (and no visible browser), use headless mode:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Set up Chrome options
options = Options()
options.add_argument(“–headless”) # Run without UI
options.add_argument(“–disable-gpu”) # Optional, helps on some systems
# Start Chrome in headless mode
driver = webdriver.Chrome(options=options)
driver.get(“https://www.example.com”)
print(“Title:”, driver.title)
driver.quit()
This skips rendering the browser, saving time—great for automated runs in CI/CD pipelines.
Debugging Selenium Scripts: Why It Matters
Tests fail for many reasons:
- Elements aren’t found (“NoSuchElementException”).
- Pages load too slowly.
- Script logic is wrong.
- ChromeDriver or browser issues.
Debugging means finding and fixing these problems. Let’s explore common issues and how to solve them with Chrome.
1. Element Not Found
If Selenium can’t find an element, it throws an error like:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element
Fix: Verify the Locator
- Inspect the Page: Right-click the element in Chrome, select “Inspect,” and check its ID, class, or other attributes.
- Test the Locator: Use Chrome DevTools’ console:
- Type document.getElementById(“username”) and press Enter. If it returns null, the ID is wrong.
Example Fix
If #username fails, try а more flexible locator like XPath:
username = driver.find_element(By.XPATH, “//input[@id=’username’]”)
Tip
Use try-except to handle missing elements gracefully:
try:
username = driver.find_element(By.ID, “username”)
username.send_keys(“tomsmith”)
except:
print(“Username field not found!”)
driver.quit()
2. Timing Issues (Element Not Ready)
If а page loads slowly, Selenium might try to find an element before it appears, causing а failure.
Slow Fix (Avoid This)
time.sleep(5) # Waits 5 seconds—wasteful!
username = driver.find_element(By.ID, “username”)
Better Fix: Explicit Waits
Wait only until the element is ready:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver.get(“https://the-internet.herokuapp.com/login”)
wait = WebDriverWait(driver, 10) # Wait up to 10 seconds
username = wait.until(EC.presence_of_element_located((By.ID, “username”)))
username.send_keys(“tomsmith”)
Why It Works
- Stops waiting as soon as the element loads.
- Avoids hard-coded delays.
Debug Tip
If it still fails, increase the timeout or check if the element’s ID changes dynamically.
3. ChromeDriver Version Mismatch
If Chrome updates but ChromeDriver doesn’t match, you’ll see errors like:
session not created: This version of ChromeDriver only supports Chrome version XX
Fix
- Check Chrome’s version: Open Chrome, go to Menu > Help > About Google Chrome.
- Download the matching ChromeDriver from chromedriver.chromium.org.
- Replace the old ChromeDriver file in your PATH.
Debug Tip
Print versions in your script:
driver = webdriver.Chrome()
print(“Chrome version:”, driver.capabilities[“browserVersion”])
print(“ChromeDriver version:”, driver.capabilities[“chrome”][“chromedriverVersion”])
driver.quit()
4. Debugging with Chrome DevTools
Chrome’s built-in DevTools are а lifesaver for debugging Selenium scripts. You can:
- Inspect elements.
- Check network activity.
- View JavaScript errors.
How to Use DevTools with Selenium
Pause the script and open DevTools manually:
driver.get(“https://the-internet.herokuapp.com/login”)
input(“Press Enter to continue…”) # Pauses script—open Chrome and inspect
username = driver.find_element(By.ID, “username”)
- Open Chrome, right-click, and select “Inspect.”
- Use the Elements tab to verify locators.
- Check the Console for JavaScript errors (e.g., “Uncaught ReferenceError”).
- Use the Network tab to see if resources load slowly.
Automating DevTools
Selenium can’t directly open DevTools, but you can use Chrome’s DevTools Protocol via libraries like selenium-wire or webdriver-manager:
from seleniumwire import webdriver # Install: pip install selenium-wire
driver = webdriver.Chrome()
driver.get(“https://www.example.com”)
# Print network requests
for request in driver.requests:
print(request.url, request.response.status_code)
driver.quit()
This logs network activity, helping you spot slow or failed requests.
How LambdaTest Helps with Chrome Test Automation
LambdaTest is аn AI-native test execution platform that takes Selenium testing to the next level. Instead of running Chrome tests on your machine, you use their online grid, which has over 3000+ real browsers, including Chrome, across different versions and operating systems. Here’s how it helps with running and debugging Chrome tests:
1. No Local Setup Needed
Locally, you install Chrome, ChromeDriver, and keep them updated. With LambdaTest:
- Everything’s ready in the cloud.
- No downloads, no version mismatches—just write your script and go.
How to Start
- Sign up at lambdatest.com.
- Get your username and access key from your profile.
2. Run Tests on Any Chrome Version
Want to test Chrome 120 on Windows 11 and Chrome 115 on macOS? LambdaTest lets you pick without owning those systems.
Example: LambdaTest Chrome Test
from selenium import webdriver
# LambdaTest credentials
username = “your_username” # Replace with yours
access_key = “your_access_key” # Replace with yours
# Chrome settings
capabilities = {
“browserName”: “Chrome”,
“version”: “latest”,
“platform”: “Windows 10”,
“build”: “Chrome Login Test”,
“name”: “Login Check”,
“headless”: True # Optional
}
# Connect to LambdaTest
driver = webdriver.Remote(
command_executor=f”https://{username}:{access_key}@hub.lambdatest.com/wd/hub”,
desired_capabilities=capabilities
)
# Run the test
driver.get(“https://the-internet.herokuapp.com/login”)
username = driver.find_element(By.ID, “username”)
username.send_keys(“tomsmith”)
password = driver.find_element(By.ID, “password”)
password.send_keys(“SuperSecretPassword!”)
login_button = driver.find_element(By.CLASS_NAME, “radius”)
login_button.click()
success_message = driver.find_element(By.ID, “flash”)
print(“Result:”, success_message.text)
driver.quit()
Why It’s Better
- Tests run on LambdaTest’s Chrome instances, not your machine.
- Pick any Chrome version or OS with capabilities.
3. Faster Execution with Parallel Testing
Locally, tests run one at а time. LambdaTest runs many Chrome tests simultaneously.
Parallel Example
Using pytest:
import pytest
from selenium import webdriver
@pytest.fixture(scope=”function”)
def driver():
capabilities = {
“browserName”: “Chrome”,
“version”: “latest”,
“platform”: “Windows 10”,
“build”: “Parallel Tests”
}
driver = webdriver.Remote(
command_executor=f”https://{username}:{access_key}@hub.lambdatest.com/wd/hub”,
desired_capabilities=capabilities
)
yield driver
driver.quit()
def test_login(driver):
driver.get(“https://the-internet.herokuapp.com/login”)
assert “Login Page” in driver.title
def test_google(driver):
driver.get(“https://www.google.com”)
assert “Google” in driver.title
Run: pytest -n 2 (2 Chrome instances). LambdaTest handles both at once.
Why It Helps
- Cuts total time (e.g., 10 minutes to 5).
- No need to set up multiple local Chromes.
4. Easy Debugging Tools
Local debugging relies on logs or manual checks. LambdaTest offers:
- Screenshots: See Chrome’s state at failure.
- Videos: Watch the full test run.
- Logs: Network, console, and Selenium logs.
Debug Example
If the login test fails, check the LambdaTest dashboard:
- Open the test session.
- View the screenshot where it broke.
- Watch the video to see Chrome’s behavior.
- Read logs for errors like “element not found.”
Why It’s Better
- No need to pause scripts or open DevTools manually.
Final Thoughts
Running and debugging Chrome tests with Selenium WebDriver is easier with LambdaTest. Locally, you juggle ChromeDriver, waits, and manual debugging.
LambdaTest offers а cloud grid with instant Chrome access, parallel testing, and built-in tools—screenshots, videos, logs, and DevTools integration—to fix issues fast. Whether you’re testing а simple page or а complex app, LambdaTest saves time, scales effortlessly, and boosts reliability. Try it with а free trial, and see how it transforms your Chrome automation!
When considering modern automation tools, the Playwright vs Cypress debate often comes up—but if you’re looking for broad browser support, robust Chrome debugging, and seamless cloud execution, Selenium with LambdaTest remains a top choice. Try it with a free trial, and see how it transforms your Chrome automation!