I've tried the following, which worked for me: the idea is to access the page source with selenium, then I search for all the strings starting with '<' and put them cleaned in a list, by removing the '<' from the start. Then I iterate the list and for each one I use value_of_css_property and search for background-color, border-color, color, background-image. I know this is not perfect but it does what I was looking for. Don't forget to remove duplicates form the tag list (since this method will give a list of all the css-color properties of each tag).
Example:
url ="someurl"
options = webdriver.ChromeOptions()
options.headless = False
driver = webdriver.Chrome(options=options)
driver.get(url)
list_tags = []
html_source = driver.page_source
txt = re.findall(r'<[a-zA-Z]+', html_source)
for x in txt:
list_tags.append(x.replace('<', ''))
list_tags = list(dict.fromkeys(list_tags))
final_list = []
for i in list_tags:
tag = driver.find_elements_by_tag_name(i)
tag_back_col = []
tag_col = []
tag_img = []
tag_border = []
for j in tag:
back_col = j.value_of_css_property('background-color')
tag_back_col.append(back_col)
col = j.value_of_css_property('color')
tag_col.append(col)
bord = j.value_of_css_property('border-color')
tag_border.append(bord)
img = j.value_of_css_property('background-image')
tag_img.append(img)
final_list .append((i, tag_back_col, tag_col, tag_border, tag_img))
driver.close()
The final list will be a list of tuples with the tag name and the lists of backgrounds-colors, colors, border-colors and background-image for each occurrence of that tag in the page.