We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
Learn the difference between HTML attributes and DOM properties, and how to fetch them.
When you interact with elements in Selenium, you're really dealing with two different "layers" of data:
Classic method with "smart" behavior. Often returns DOM property for fields like value.
Selenium 4. Reads HTML attribute only. Good for checking initial/default values.
Selenium 4. Reads DOM property only. Always reflects current live state.
id="demo-input" • Initial value="Initial Value"
"Initial Value"
Stays the same as written in HTML
"Initial Value"
Updates in real time as you type
Type in the input to see how HTML attribute stays constant while DOM property updates!
Initial Value.Hello Selenium."Initial Value""Hello Selenium"123456789WebElement input = driver.findElement(By.id("demo-input"));
String classicValue = input.getAttribute("value");
String htmlAttributeValue = input.getDomAttribute("value");
String domPropertyValue = input.getDomProperty("value");
System.out.println("getAttribute: " + classicValue);
System.out.println("getDomAttribute: " + htmlAttributeValue);
System.out.println("getDomProperty: " + domPropertyValue);"Initial Value" even after typing.Use getDomProperty("value") to assert what the user actually typed.
Use getDomAttribute("value") to verify initial/default values in HTML.
Use clear naming (defaultValue, currentValue) in your test code.