How to determine colors using Selenium?


Selenium has the color conversion support class. We have to add the statement from selenium.webdriver.support.color import Color to convert colors to rgba/hex format.

Example

from selenium import webdriver
from selenium.webdriver.support.color import Color

#color conversion to rgba format
print(Color.from_string('#00fe37').rgba)

#color conversion to hex format
print(Color.from_string('rgb(1, 200, 5)').hex)

#color conversion to rgba format
print(Color.from_string('green').rgba)

Output

Updated on: 08-Feb-2022

845 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements