【发布时间】:2022-01-22 18:24:55
【问题描述】:
您好,我正在使用 python selenium 来获取按钮的一些 css 属性。我还需要悬停背景颜色。 css是这样的:
.overview .add-to-cart-button:hover, .variant-overview .add-to-cart-button:hover {
background-color: #b41733;}
我的代码是这样的:
from selenium import webdriver
from selenium.webdriver.support.color import Color
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(executable_path = ChromeDriverManager().install())
driver.get('https://www.inshoes.gr/andrikes-zones-andrikes-zones-dermatines-diplis-opseos-33000481-kamel-mavro')
background_color = driver.find_element_by_id('addtocartbutton-7531').value_of_css_property('background-color')
text_color = driver.find_element_by_id('addtocartbutton-7531').value_of_css_property('color')
hex_color = Color.from_string(background_color).hex
hex_text_color = Color.from_string(text_color).hex
print(hex_color)
print(hex_text_color)
有人可以帮我吗?
【问题讨论】:
-
print(hex_color)和print(hex_text_color)打印什么? -
@DebanjanB 按钮的背景颜色和文本颜色。悬停按钮时需要背景颜色
标签: python selenium selenium-webdriver webdriverwait value-of-css-property