Getting Started with DevTools for Selenium & Playwright: How to Use the Elements, Console, and Network Panels

When writing test code with Selenium or Playwright, have you ever struggled with “Which selector should I use?” or “Why can’t I find this element?” Mastering your browser’s Developer Tools (DevTools) can solve most of those problems. This guide covers the DevTools fundamentals every QA engineer needs for test automation — with practical examples throughout.

📌 Who This Article Is For

✅ Beginners with Selenium or Playwright who are unsure how to locate elements
✅ Engineers who have opened DevTools before but aren’t sure what to look at
✅ QA engineers who want to build solid foundational skills before writing test code
✅ Anyone who wants to speed up bug investigation during manual testing

✅ What You’ll Learn

  • Understand the role of the four tabs QA engineers use most often
  • Verify and copy selectors for Selenium and Playwright on the spot
  • Use the Network tab to inspect API responses and strengthen test design
  • Investigate bugs faster during manual testing sessions

👨‍💻 About the Author

This article is written by a QA engineer with over 15 years of hands-on experience in test automation using Selenium and Playwright. The content is grounded in real situations — including the all-too-familiar experience of opening DevTools and having no idea where to start.

📌 Key Takeaways

  • Mastering the Elements, Console, and Network tabs will significantly improve your testing efficiency
  • Start selector verification with Elements tab → right-click → Copy
  • Use $$('selector') in the Console tab to validate selectors in real time

“Element not found.” “I have no idea which selector to use.” These are the walls every beginner hits when starting out with test automation. The good news: most of the answers are already inside your browser’s Developer Tools (DevTools).

DevTools is a built-in development and debugging panel available in Chrome, Edge, Firefox, and other modern browsers — no installation required. For QA engineers, it’s an indispensable companion for preparing and verifying test code before you write a single line.

What Is Chrome DevTools?

DevTools is a built-in panel in your browser for development and debugging. It lets you inspect a page’s HTML structure, CSS, JavaScript behavior, and network communication — all in real time.

How to Open DevTools

OS / BrowserShortcutAlternative
Windows / Chrome · EdgeF12 or Ctrl + Shift + IRight-click → “Inspect”
Mac / Chrome · SafariCmd + Option + IRight-click → “Inspect Element”
FirefoxF12 or Ctrl + Shift + IRight-click → “Inspect”

In QA practice, Chrome DevTools is the most widely used. Since Selenium and Playwright both default to Chromium-based browsers, what you see in Chrome DevTools maps directly to your test code.

① Elements Tab: Inspect Elements and Grab Selectors

This is the tab QA engineers use most. It shows the page’s HTML structure and lets you copy selectors for use in your test code — right on the spot.

Finding an Element Quickly

Right-click on the element you want to test (a button, input field, etc.) and select “Inspect.” The element will be highlighted in the HTML tree.

Right-click the target elementSelect “Inspect”Element highlighted in the Elements tab

Copying Selectors

Right-clicking an HTML element in the Elements tab gives you a one-click way to copy its selector.

Copy MethodWhat You GetRecommendation
Copy → Copy selectorCSS selector⭐⭐⭐ Start here
Copy → Copy XPathXPath (relative)⭐⭐ When CSS isn’t enough
Copy → Copy full XPathXPath (absolute)⭐ Last resort — breaks easily

⚠️ Avoid Copy Full XPath

Absolute XPath like /html/body/div[2]/main/section[1]/form/input[3] breaks the moment the page structure changes even slightly. It leads to high maintenance costs. When a stable attribute like id or data-testid exists, always prefer that instead.

Checking id and data-testid Attributes

The Elements tab shows all attributes on an element — id, name, data-testid, and more — at a glance.


<input id="email"
       name="email"
       data-testid="login-email"
       type="email"
       placeholder="Email address">

With that information, you can write the following in Selenium or Playwright:

# Selenium
driver.find_element(By.ID, "email")
driver.find_element(By.CSS_SELECTOR, "[data-testid='login-email']")

# Playwright
page.get_by_test_id("login-email")
page.locator("#email")

② Console Tab: Validate Selectors in Real Time

The Console tab lets you run JavaScript directly in the browser. Use it to verify whether a selector actually matches an element — before writing a single line of test code.

Selector Verification Quick Reference

# Get the first matching element by CSS selector
document.querySelector('.submit-btn')

# Get all matching elements (full syntax)
document.querySelectorAll('.list-item')

# Shortcuts available in the Chrome DevTools Console only
$$('.list-item')             # Shorthand for document.querySelectorAll
$x('//button[@type="submit"]')  # XPath query

# Check an attribute value
document.querySelector('#email').getAttribute('data-testid')

If $$('.list-item') returns an empty array [], the selector isn’t matching anything — refine it and try again.

💡 How to Read Console Results

ResultMeaning
<input id="email"...>✅ Element found successfully
null❌ Selector doesn’t match (querySelector)
[] (empty array)❌ Selector doesn’t match ($$ or $x)
[input#email, input.email-field]⚠️ Multiple matches — narrow it down further

③ Network Tab: Inspect API Communication

The Network tab shows all HTTP requests the page makes in real time. It’s essential for understanding what’s happening between the frontend and the API — and for building your test cases around actual data.

Network Tab Information Useful for Test Design

What You Can SeeHow It Helps with Testing
Request URL and methodIdentify the exact API endpoint to target in your API tests
Request bodyConfirm parameter names and data format being sent
Response bodyCheck the expected JSON for success and error responses
Status codeTurn 200/400/401/500 patterns into concrete test cases
Response timeInvestigate slow page rendering and confirm response performance

Network Tab Filters

The Network tab captures all traffic, which can feel overwhelming at first. Use these filters to narrow things down quickly.

FilterUse Case
Fetch/XHRShow only API calls. The most commonly used filter
DocShow only HTML document requests
Img / MediaImage and media file requests
Search boxFilter by URL keyword (e.g., api/login)

④ Application Tab: Inspect Cookies and Storage

The Application tab is useful for testing login state, session management, and other storage-based behavior. You can view and delete Cookie and LocalStorage values in real time.

FeatureTesting Use Case
CookiesCheck session token presence and expiry. Delete to simulate logged-out state
LocalStorageInspect frontend-stored settings and user data
SessionStorageCheck temporary data that resets when the tab closes

Common Pitfalls When Using DevTools

🚧 Watch Out for These

① No network log in the Network tab after opening DevTools

The Network tab only records traffic while it’s open. Open DevTools before reloading the page, or re-trigger the action you want to capture.

② The CSS selector copied from DevTools doesn’t work in Selenium

Chrome-generated CSS selectors often look like #main > div:nth-child(2) > button — they’re fragile structure-based paths. Rewrite them using id, name, or data-testid attributes for stable, maintainable tests.

$$('.btn') works in Console but the element isn’t found in the test

Dynamically rendered elements may appear some time after the initial page load. Use Selenium’s WebDriverWait or Playwright’s built-in auto-waiting to wait for the element to appear.

④ Can’t interact with elements inside an iframe

Content inside an iframe is treated as a separate document, so it can’t be accessed the same way as regular page elements. In Selenium, use driver.switch_to.frame(); in Playwright, use frame_locator().

⑤ Confused by XHR and Fetch appearing as separate entries

In Chrome, the “Fetch/XHR” filter shows both together in one view. If they appear separately, click each to inspect them individually.

DevTools Tab Quick Reference by Task

What You Want to DoTab to UseHow
Check an element’s id or classElementsRight-click → “Inspect”
Copy a CSS selectorElementsRight-click element → Copy → Copy selector
Verify a selector worksConsoleRun $$('selector')
Inspect an API request or responseNetworkFilter by Fetch/XHR
Check login cookiesApplicationCookies → select the domain
Investigate what caused an errorConsole + NetworkRed error messages + failed requests

Frequently Asked Questions

Q. Which browser should I use for DevTools?

Google Chrome is the top recommendation for test automation purposes. Selenium and Playwright both default to Chromium-based browsers, so what you verify in Chrome DevTools applies directly to your test code.

Q. Should I verify selectors in the Elements tab or the Console tab?

Both, in sequence. First use the Elements tab to identify id, data-testid, or other attributes. Then validate the selector using $$('...') in the Console tab. This two-step approach is fast and reliable.

Q. What’s the difference between $, $$, and $x in the Console?

$ is shorthand for document.querySelector (first match only), $$ is shorthand for document.querySelectorAll (all matches), and $x queries by XPath. These are shortcuts available in the Chrome DevTools Console and cannot be used in your JavaScript code or in Selenium/Playwright test code. Note that $x in particular is a Chrome DevTools-specific feature and may change in future versions.

Q. There’s a CORS error in the Network tab. Will it affect my tests?

CORS errors are browser security restrictions and usually do not directly affect Selenium or Playwright test runs. However, if your API tests make cross-origin requests, check that your test environment’s CORS settings are configured correctly.

Q. Should I use Playwright Codegen or DevTools?

They serve different purposes. Playwright Codegen (playwright codegen) records browser actions and generates test code automatically — great for reducing boilerplate. DevTools is your go-to for bug investigation during manual testing, pre-verifying selectors, and inspecting API responses. Using both together gives you the best results.

Q. Can a selector verified in DevTools break in a different environment?

Yes. Selectors based on randomly generated ids or dynamically assigned class names (e.g., CSS Modules generating Button_btn__abc123) can vary by environment or build. The best practice is to ask developers to add dedicated data-testid attributes that remain consistent across environments.

Q. Are Chrome DevTools and Edge DevTools different?

They are essentially the same. Since Edge is also Chromium-based, all major features — Elements, Console, Network, and more — work identically. Either browser works fine for Selenium and Playwright verification purposes.

Summary

  • Elements tab: Inspect HTML structure and copy CSS selectors or XPath
  • Console tab: Validate selectors instantly using $$('selector')
  • Network tab: Use the Fetch/XHR filter to inspect API requests, responses, and status codes
  • Application tab: Check and reset Cookies and LocalStorage for login and session testing
  • “Copy full XPath” breaks easily — prefer id or data-testid attributes whenever possible

DevTools requires no installation — it’s waiting in your browser right now. Building the habit of “check DevTools first before writing test code” is one of the simplest and highest-impact things you can do to improve both the quality of your tests and the speed of your debugging.

💡 A Note for Playwright Users: Use Semantic Locators for More Stable Tests

Beyond page.locator("#email"), Playwright recommends the following locators for better stability. Use DevTools to identify the role, label, or testid of your target element, then pick the right one.

LocatorWhen to Use
page.get_by_role("button", name="Submit")Buttons, links, and other interactive roles
page.get_by_label("Email address")Input fields associated with a label
page.get_by_test_id("login-email")data-testid attributes — the most stable option

📚 Related Articles

タイトルとURLをコピーしました