Selenium WebElement has 2 methods, in Python, they are 'get_attribute' and 'get_property' . The documentation is very simple and unclear to me.
What is the difference of them on earth?
Selenium WebElement has 2 methods, in Python, they are 'get_attribute' and 'get_property' . The documentation is very simple and unclear to me.
What is the difference of them on earth?
An attribute is a static attribute of a given DOM node, as where a property is a computed property of the DOM node object. An example of a property would be the checked
state of a checkbox, or value
or an input field. As where an attribute would be href
of an anchor tag or the type
of an input DOM.
<a href="https://google.com" id="hello">Hello World</a>
<input type="checkbox" id="foo" checked>
<input type="text" id="bar" value="cheesecake">
link_location = document.querySelector('#hello').getAttribute('href')
// # href="https://google.com"
input_checkbox = document.querySelector('#foo').getAttribute('type')
// # type="checkbox"
checkbox_checked = document.querySelector('#foo').checked
// # computed property of the DOM node
textbox_value = document.querySelector('#bar').value
// # computed property of the DOM node
Seems that get_attribute
search for properties and then attributes and get_property
just for properties.
From code documentation
get_property
def get_property(self, name):
"""
Gets the given property of the element.
:Args:
- name - Name of the property to retrieve.
get_attribute
def get_attribute(self, name):
"""Gets the given attribute or property of the element.
This method will first try to return the value of a property with the
given name. If a property with that name doesn't exist, it returns the
value of the attribute with the same name. If there's no attribute with
that name, ``None`` is returned.
Values which are considered truthy, that is equals "true" or "false",
are returned as booleans. All other non-``None`` values are returned
as strings. For attributes or properties which do not exist, ``None``
is returned.
:Args:
- name - Name of the attribute/property to retrieve.