Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 810
Raj Sahoo Avatar asked Oct 26 '17 09:10

Raj Sahoo


1 Answers

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))
like image 85
Andersson Avatar answered Oct 23 '22 04:10

Andersson