You might have noticed a few Selenium methods in Python that seem quite similar: get_attribute, get_property, and get_dom_attribute. So, which one should you use, and what’s the difference between them?
Each of these methods works a little differently, and the best choice depends on what you’re trying to do. Let’s break it down!
- get_property() method in Selenium Python is used to get only the value of the element’s property.
- get_dom_attribute() method in Selenium Python is used to retrieve only the value of an element’s attribute, not its property. Some attributes and properties might share the same name, but that doesn’t mean
get_dom_attribute()
will return the property value. It strictly fetches the attribute value from the DOM. It always fetches the attribute value only. - get_attribute() method can be considered as a combination of the above two methods ( get_property + get_dom_attribute ).
- So, what does it mean? The
get_attribute()
method in Selenium Python first tries to retrieve the property value of the name passed as its argument. If a property with that name does not exist, only then does it returns the value of the attribute with the same name,
- So, what does it mean? The
So, which one to use?
Now that we know what each method does, which one should we use?
- It’s best to avoid using get_attribute(), as Selenium might deprecate it in the future.
- Use get_dom_attribute() when you need to fetch an attribute’s value, and use get_property() when you need to retrieve a property’s value.
Okay, we won’t be using get_attribute(), but how can we then decide between get_dom_attribute() and get_property()?
Well, for that, we first need to understand the difference between an attribute and a property.
Attribute vs Property
Attributes provide additional information about the elements, and all tags can have attributes that provide more information about them.
For example, we have the “type” and “id” attributes on the <input> tag.
<input type="text" id = "firstName">
Here type and id are the attribute keys, whereas text and firstName are their values, respectively.

When the browser parses the HTML, it converts the HTML attributes to DOM properties.
So, for input tag –
<input type="text" id = "firstName">
type and id are the attributes.
When the browser parses the HTML, it will create a DOM property of the attributes, which can be read using input.type or input.id.
Please note that all HTML attributes are not converted to properties with the same name. E.g., class attribute is converted to the className property.
In a nutshell, we can say that an attribute is related to HTML, whereas a property is associated with DOM.
Now, how to choose between get_dom_attribute() and get_property()?
We can easily find the answer using Developer Tools.
Open Chrome Developer Tools and inspect any element on this page to explore its attributes and properties: https://testkru.com/Elements/TextFields.

If you want to retrieve any attribute’s value shown in the image, you should use the get_dom_attribute() method.
Now, there is a Properties tab in the bottom section. Click on it.

It also displays a list of key-value pairs. Everything shown there represents a property, and you can retrieve their values using the get_property() method.
That’s it! We hope you now have a clearer understanding of the get_attribute, get_property, and get_dom_attribute methods and when to use each one.. If you have any doubts or concerns, please feel free to write us in the comments or mail us at admin@codekru.com.