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:
Although the message is not present in the DOM, it can be accessed through the underlying DOM elementโs JavaScript property:
The validationMessage property is part of the HTMLInputElement API and provides the localized validation message associated with the element.
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:
With this simple configuration, the browser automatically:
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
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.
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.
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.
Confirms whether the field passes validation rules.
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.