Introduction
The get_property() method is one of Selenium 4’s WebElement methods used to retrieve the current JavaScript property value of a web element. Unlike HTML attributes, JavaScript properties can change dynamically during runtime as users interact with a webpage.
Modern web applications heavily rely on JavaScript to update element states such as whether a checkbox is selected, whether a button is enabled, or whether an input field contains a particular value. The get_property() method allows automation engineers to retrieve these live property values accurately during test execution.
In this tutorial, you’ll learn what get_property() is, why it is used, its syntax, practical examples, real-world use cases, common mistakes, and best practices.
What is get_property()?
The get_property() method returns the current JavaScript property value associated with a web element.
Unlike get_attribute() and get_dom_attribute(), which retrieve HTML attribute values, get_property() retrieves the element’s current runtime state maintained by JavaScript.
For example, consider the following HTML:
<input
type="checkbox"
checked>
When the user interacts with the checkbox, JavaScript may update its current state during execution.
Selenium can retrieve this property using:
element.get_property(
"property_name"
)
The get_property() method is commonly used for retrieving:
checked
value
disabled
selected
hidden
readOnly
textContent
Other JavaScript properties
Why Use get_property()?
The get_property() method is useful because it:
Retrieves current JavaScript property values.
Reflects the element’s runtime state.
Improves automation reliability.
Supports dynamic UI validation.
Produces readable automation scripts.
Is extensively used in Selenium 4 automation frameworks.
Syntax
element.get_property(
"property_name"
)
Where:
element→ Previously located WebElement."property_name"→ Name of the JavaScript property.get_property()→ Returns the property’s current value.
Difference Between Attribute, DOM Attribute, and Property
| Method | Returns |
|---|---|
| get_attribute() | Current attribute or property value |
| get_dom_attribute() | Original HTML attribute value |
| get_property() | Current JavaScript property value |
For example:
<input
type="checkbox"
checked>
Initially:
Attribute Value
│
▼
checked
DOM Attribute
│
▼
checked
Property Value
│
▼
True
If the user deselects the checkbox:
Attribute Value
│
▼
checked
DOM Attribute
│
▼
checked
Property Value
│
▼
False
Notice that only the property’s value changes dynamically during runtime.
Example
The Selenium practice website contains two checkboxes. Selenium retrieves the checked property of the second checkbox and verifies that it is currently selected.
The Selenium code is:
from selenium import webdriver
from selenium.webdriver.common.by import By
# Topic: 17. Retrieving Element Information - get_property()
# Practice site: https://the-internet.herokuapp.com/checkboxes
# Run: pytest -s 17_examples/test_04_get_property.py
#
# get_property() returns JavaScript object properties such as checked on
# checkboxes.
def test_get_property():
driver = webdriver.Chrome()
try:
driver.get(
"https://the-internet.herokuapp.com/checkboxes"
)
checkbox = driver.find_elements(
By.CSS_SELECTOR,
"input[type='checkbox']"
)[1]
assert checkbox.get_property(
"checked"
) is True
finally:
driver.quit()
Output
The checkbox's checked
property is retrieved
successfully and confirms
that the element is
currently selected.
Understanding the Code
Import the By Class
from selenium.webdriver.common.by import By
Imports Selenium’s locator strategies.
Open the Practice Website
driver.get(
"https://the-internet.herokuapp.com/checkboxes"
)
Launches the Selenium practice website.
Locate the Checkbox
driver.find_elements(
By.CSS_SELECTOR,
"input[type='checkbox']"
)[1]
Locates the second checkbox displayed on the webpage.
Retrieve the Property Value
checkbox.get_property(
"checked"
)
Returns:
True
which represents the checkbox’s current runtime state.
Validate the Result
assert checkbox.get_property(
"checked"
) is True
Verifies that the checkbox is currently selected.
How get_property() Works
Python Script
│
▼
Locate Web Element
│
▼
get_property()
│
▼
Read JavaScript Property
│
▼
Retrieve Current Value
│
▼
Compare Values
│
▼
Perform Validation
Practical Example
Suppose you’re automating a Registration page.
The user selects:
Accept Terms and Conditions
Selenium can validate the current checkbox state using:
checkbox.get_property(
"checked"
)
which returns:
True
This accurately reflects the user’s current interaction with the webpage.
Automation Testing Example
Consider an online banking application.
Automation engineers frequently validate:
Selected checkboxes.
Disabled buttons.
Input field values.
Toggle switches.
Form states.
User interactions.
Professional automation frameworks extensively use get_property() while testing modern JavaScript-based applications during regression testing.
Real-World Example
Automation engineers frequently use get_property() while automating:
Banking applications.
E-Commerce websites.
Healthcare portals.
CRM systems.
ERP applications.
SaaS products.
Enterprise web applications.
Registration forms.
Dynamic dashboards.
Property-level validation has become increasingly important because modern applications rely heavily on JavaScript-based interactions.
Advantages of get_property()
Retrieves current JavaScript property values.
Reflects runtime changes accurately.
Improves automation reliability.
Supports dynamic UI validation.
Produces maintainable automation scripts.
Extensively used in Selenium 4.
Commonly Retrieved Properties
Some frequently used JavaScript properties include:
checked
value
disabled
selected
hidden
readOnly
textContent
innerHTML
These properties are commonly validated during Selenium automation testing.
Common Mistakes Beginners Make
Confusing Properties with Attributes
Incorrect Assumption
get_attribute()
and:
get_property()
always return the same value.
This is not necessarily true.
For example:
get_attribute()
│
▼
May Return Current
Attribute Values
get_property()
│
▼
Returns Current
JavaScript Property Values
Understanding the distinction is extremely important while working with dynamic webpages.
Using Incorrect Property Names
Incorrect
checkbox.get_property(
"check"
)
Correct
checkbox.get_property(
"checked"
)
Always verify JavaScript property names using browser Developer Tools.
Ignoring Dynamic Property Changes
Remember that:
get_property()
returns:
Current Runtime Values
whereas:
get_dom_attribute()
returns:
Original HTML Values
Choose the appropriate method based on your testing requirements.
Best Practices
Use
get_property()when validating dynamic JavaScript properties.Use
get_dom_attribute()when validating original HTML attributes.Verify property names using browser Developer Tools.
Validate runtime values whenever appropriate.
Keep assertions simple and readable.
Use synchronization techniques for dynamically updated webpages.
Conclusion
The get_property() method introduced in Selenium 4 provides automation engineers with accurate access to an element’s current JavaScript property values. It plays a critical role in validating dynamic user interactions and runtime changes within modern web applications.
Understanding the differences between get_attribute(), get_dom_attribute(), and get_property() is essential for building scalable, reliable, and maintainable Selenium automation frameworks.
Frequently Asked Questions (FAQs)
What is get_property() in Selenium?
The get_property() method returns the current JavaScript property value associated with a web element.
What is the syntax of get_property()?
element.get_property(
"property_name"
)
What is the difference between get_property() and get_attribute()?
get_property()→ Returns current JavaScript property values.get_attribute()→ Returns attribute values and, in some cases, property values.
Is get_property() available in Selenium 3?
No.
get_property() was introduced in Selenium 4.
When should I use get_property()?
Use it when:
Validating checkbox states.
Testing dynamically updated webpages.
Verifying JavaScript property values.
Performing runtime UI validation.
Key Takeaways
get_property()retrieves current JavaScript property values.It accurately reflects an element’s runtime state.
Use it for validating dynamic user interactions such as selected checkboxes and disabled buttons.
It differs from both
get_attribute()andget_dom_attribute().Verify property names before performing assertions.
get_property()is extensively used in Selenium 4 automation frameworks.
