How to find the background color of a web element in hexadecimal format? With my current selenium webdriver python code, it returns the background color in RGB format.
This is the html element I'm viewing
div class="bar" style="background-color: #DD514C; background-image: -moz-linear-gradient(center top , #EE5F5B, #C43C35); background-image: -webkit-linear-gradient(top , #EE5F5B, #C43C35); background-image: -ms-linear-gradient(top , #EE5F5B, #C43C35); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#EE5F5B, endColorstr=#C43C35, GradientType=0); background-repeat: repeat-x; color: #ffffff; width: 11.5%"
My python code for webdriver:
find_element_by_class_name("bar").get_attribute("style")
It returns a style with colors in rgb format. I want to get the background color in hexadecimal so that I can compare it with my expected value. Now I get the following result:
background-color: rgb(221, 81, 76); background-image: -moz-linear-gradient(center top , rgb(238, 95, 91), rgb(196, 60, 53)); background-repeat: repeat-x; color: rgb(255, 255, 255); width: 11.5%;
python selenium automation selenium-webdriver
nids
source share