Raj Sahoo
Raj Sahoo

Reputation: 496

How to retrieve all the css properties of an element using selenium python?

value_of_css_property(property_name) returns value for a particular property.

But I want know if there is any way we can get all the css properties?

Upvotes: 7

Views: 6683

Answers (2)

Christian Will
Christian Will

Reputation: 1695

element.get_property('style') will give you all the properties

example:

print(e.get_property('style'))
['height', 'width', 'visibility', 'position', 'z-index', 'font-family', 'font-size', 'font-weight', 'font-style']

Upvotes: 0

Andersson
Andersson

Reputation: 52675

Try below to get property names:

element = driver.find_element_by_tag_name('a')
properties = driver.execute_script('return window.getComputedStyle(arguments[0], null);', element)

or to get all values of properties

element = driver.find_element_by_tag_name('a')
properties = driver.execute_script('return window.getComputedStyle(arguments[0], null);', element)
for property in properties:
    print(element.value_of_css_property(property))

Upvotes: 14

Related Questions