Testleaf

Selenium DOM Properties Explained: Fix Hidden Error Messages

https://www.testleaf.com/blog/wp-content/uploads/2025/08/Selenium-DOM-Properties-Explained-Fix-Hidden-Error-Messages.mp3?_=1

Introduction 

As testers, we often interact with web elements using DOM (Document Object Model) properties such as id, name, class, etc. But have you ever encountered an error message in the browser that is not visible in the DOM, cannot be inspected, and doesn’t even freeze with tools like dev tools or XPath plugins? 

In this blog, we’ll uncover a powerful concept: DOM properties that are not part of the HTML DOM tree, and how Selenium gives us access to them — with a special focus on validationMessage. 

What Is a DOM Property? 

A DOM property is a runtime JavaScript object property associated with an HTML element. It exists in the browser’s memory (DOM tree), and it’s different from HTML attributes. 

HTML Attribute  DOM Property 
value=”123″  element.value 
type=”text”  element.type 
No visible attribute  element.validationMessage 

DOM properties can change at runtime and are not always directly visible in the HTML source or inspector. 

The Problem: Error Message Not in DOM 

Consider this scenario: 

You try to login to a site with an invalid email like ”shan” — and the browser throws an error: 

“Please include an ‘@’ in the email address. ‘shan’ is missing an ‘@’.” 

However, this message: 

  • Is not visible in the DOM 
  • Cannot be inspected 
  • Cannot be frozen 
  • Doesn’t appear as a tooltip in dev tools 

Then how do we access it in Selenium? 

Popular Articles: product based companies in bangalore

The Hidden Power:  

validationMessage : 

Selenium allows you to access this built-in browser validation message using: 

String message = element.getAttribute(“validationMessage”); 

System.out.println(message); 

Why It Works: 

  • The validationMessage is a DOM property from the Constraint Validation API (built into modern browsers). 
  • It is generated dynamically based on the type, required, pattern, or min/max attributes on form fields. 

 

Real-Time Selenium Script: Catch Hidden Validation

WebDriver driver = new ChromeDriver(); 

driver.get(“https://acme-test.uipath.com/login”); 

WebElement email = driver.findElement(By.id(“email”)); 

email.sendKeys(“shan”);  // Invalid email format 

WebElement password = driver.findElement(By.id(“password”)); 

password.sendKeys(“qeagle@123”); 

driver.findElement(By.xpath(“//button[@type=’submit’]”)).click(); 

String errorMsg = email.getAttribute(“validationMessage”); 

System.out.println(errorMsg); 

driver.quit(); 

Output: 

“Please include an ‘@’ in the email address. ‘shan’ is missing an ‘@’.” 

Even though this message is not in the DOM, we retrieved it using a DOM property! 

Why Can’t We Inspect These Messages? 

Because these are: 

  • Rendered by the browser natively (not by HTML or JavaScript code) 
  • Not part of the inspectable DOM structure 
  • Displayed as tooltips or overlays directly by the browser engine (like Chrome or Firefox) 

 

Other Useful DOM Properties: 

Property  Purpose 
validationMessage  Gives browser-generated validation error 
validity  Returns a ValidityState object with constraint flags 
willValidate  Indicates if the field is subject to validation 
checkValidity()  Returns true/false based on validation rules 
setCustomValidity()  Allows setting a custom validation message 

Real-Time Use Cases in Testing 

  • Form validation (email, password, phone number, etc.) 
  • Required field check 
  • Pattern mismatch 
  • Min/max validation 

All these validations may show browser-native tooltips — you can still access them with validationMessage. 

 

Conclusion 

In modern web testing, not everything visible is inspectable — and not everything inspectable is reliable. Sometimes, the most important validation errors live silently in the DOM properties, not in the HTML source. 

Understanding and using DOM properties like validationMessage opens a powerful new way to automate edge-case validations that many testers overlook. 

If you’re diving deep into such concepts, a selenium automation testing course can sharpen your skills and help you uncover what most testers miss.

 

FAQs

Q1. What is validationMessage in Selenium?
A built-in DOM property that shows browser-generated form validation error messages, even if they’re not in the HTML DOM.

Q2. Why can’t I inspect browser error messages in dev tools?
Because they’re rendered by the browser engine, not HTML or JavaScript, and are shown as tooltips.

Q3. How do I retrieve hidden error messages in Selenium?
Use element.getAttribute("validationMessage") to access the dynamic browser message.

Q4. Is validationMessage available in all browsers?
Yes, it is supported in all modern browsers via the Constraint Validation API.

Q5. Can I use AI tools to enhance Selenium testing?
Absolutely. Tools like AI-powered test generators can complement DOM property-based validations for smarter automation.

We Also Provide Training In:
Author’s Bio:

As a Senior SDET, I’m passionate about advancing the field of test automation by equipping teams with real-time solutions and high-impact frameworks. With over 8 years of experience in software testing and development, I specialize in building scalable automation platforms that ensure quality at speed. I’m committed to mentoring aspiring engineers and driving innovation through continuous learning and technical excellence. Let’s shape the future of quality engineering—together.

Dilipkumar Rajendran
Senior SDET | Playwright & Selenium Expert

Accelerate Your Salary with Expert-Level Selenium Training

X
Exit mobile version