Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain CSS value (eg. color) of element using selenium webdriver in Python

I know in Java one could use getCSSvalue so is there any equivalent in Python?

like image 944
L P Avatar asked Jun 03 '14 13:06

L P


People also ask

How will you get the color of an element using Selenium?

We can verify the color of a webelement in Selenium webdriver using the getCssValue method and then pass color as a parameter to it. This returnsthe color in rgba() format. Next, we have to use the class Color to convert the rgba() format to Hex. Let us obtain the color an element highlighted in the below image.

What is the WebElement method used to get the backgroud color of an element displayed in the webpage?

We can verify the color and background color of a web element in Selenium with the help of getCSSValue() method.

What is CSS value in Selenium?

A CSS Selector is a combination of an element selector and a value which identifies the web element within a web page. They are string representations of HTML tags, attributes, Id and Class.


1 Answers

element.value_of_css_property(property_name) should be the Python's Selenium Webdriver equivalent of getCSSvalue().

Documentation can be found on the readthedocs page: Link

like image 60
Nahkki Avatar answered Sep 25 '22 08:09

Nahkki