Handling HTML5 Native Validation Messages in Playwright
Posted by Sonali Kolambe
Posted on 22nd Mar 2026 12:09 AM
( 20 min Read & 30 min Implementation )

#html5 #validation-message-issue #playwright
Article Outline


The Problem Statement


Consider a scenario where you attempt to validate a required field error message such as: "Please fill out this field."


During automation, the following challenges are encountered:

  1. The validation message cannot be reliably inspected using browser developer tools
  2. The message does not exist within the HTML DOM structure
  3. Locator strategies (XPath, CSS, or tools like SelectorsHub) fail to identify the element


"Please fill out this field" message




Developer Tool Investigation





Although the message is not present in the DOM, it can be accessed through the underlying DOM elementโ€™s JavaScript property:


$x("//input[@id='fullName']")[0].validationMessage




The validationMessage property is part of the HTMLInputElement API and provides the localized validation message associated with the element.



Root Cause Analysis


HTML5 introduced built-in form validation features such as required, type="email", pattern, and more. These validations significantly improve user experience by preventing invalid data submission directly at the browser levelโ€”without requiring additional JavaScript or backend checks.


Example:

<input type="email" required/>


With this simple configuration, the browser automatically:

  1. Blocks form submission if the field is empty or invalid
  2. Displays an error message (e.g., โ€œPlease enter a valid email addressโ€)
  3. Highlights the input field


Validation Messages Are Not Truly in the DOM


Unlike custom error messages, browser-generated validation messages are not standard HTML elements. They are rendered internally by the browser. This means we cannot locate them using XPath/CSS selectors and tools like Selenium or Playwright cannot directly assert them



Inconsistent Across Browsers


Different browsers display different validation messages:

Chrome: โ€œPlease fill out this field.โ€
Firefox: โ€œPlease fill in this field.โ€

This makes text-based assertions unreliable and flaky.



Locale and Language Dependency


Validation messages change based on browser language settings.

English โ†’ โ€œPlease enter a valid email addressโ€
Hindi โ†’ Localized equivalent

This introduces instability in cross-region test execution.




Solution implementation in Playwright



Using evaluate function


To retrieve this message in Playwright, it is necessary to execute code within the browser context using the .evaluate() function. This allows direct access to element properties that are not available through the DOM.





Using checkValidity function


const isValid = await page.$eval('#email', el => el.checkValidity());
expect(isValid).toBe(false);


Confirms whether the field passes validation rules.



Conclusion


HTML5 form validation is excellent for improving user experience with minimal effort. However, from an automation perspective, it introduces limitations due to its browser-controlled nature. and with time all automation tool improving themselves by introducing many new approach and implementation like checkValidity() and evaluate() function.


Related Articles
Stop Writing Syntax: Welcome to the Era of AI-Driven Development (AIDD)

Python - Constant is a myth. We all are adults here

Understanding Python Collection Symbols: A Simple Memory Technique

Decorator in Python

Meet the Computer 13,000ร— Faster Than Todayโ€™s Machines โ€” Googleโ€™s Willow Chip Runs OTOC Quantum Echoes

Test Report Metrics - Real Face of QA Process

๐—ฆ๐—ฒ๐˜๐˜‚๐—ฝ ๐—š๐—ผ๐—ผ๐—ด๐—น๐—ฒ ๐—–๐—น๐—ผ๐˜‚๐—ฑ ๐—–๐—ฟ๐—ฒ๐—ฑ๐—ฒ๐—ป๐˜๐—ถ๐—ฎ๐—น๐˜€ ๐—ข๐—”๐˜‚๐˜๐—ต ๐Ÿฎ.๐Ÿฌ ๐—ถ๐—ป ๐—ผ๐—ฟ๐—ฑ๐—ฒ๐—ฟ ๐˜๐—ผ ๐—ฎ๐—ฐ๐—ฐ๐—ฒ๐˜€๐˜€ ๐—š๐—ผ๐—ผ๐—ด๐—น๐—ฒ ๐—ฆ๐—ต๐—ฒ๐—ฒ๐˜๐˜€ ๐—”๐—ฃ๐—œ๐˜€

A Step-by-Step Guide to Creating Service Accounts in Google APIs

Read Data From Google-Sheet

@DataProvider and @Factory Annotation in TestNG

Implement Logger in your java framework

Unlocking Database Power: A Comprehensive Guide to JDBC in Java

GoLang, Go Fast - Digitalizing Faster World

Scrum vs Kanban: The Battle of Agile Methodologies

The Rise of Codeless QA: Tools Transforming Software Quality

Fibonacci Series in Sprint Velocity

Manage Competing Work Demand Prioritization Framework - MoSCoW and Eisenhower

Canary Trap - information security and detecting leaks

Verification and Validation

Introduction of Keys in DBMS

All Comments ()
Do You want to add Comment in this Blog? Please Login ?