获取页面元素的颜色value_of_css_property('color')
from selenium import webdriver from selenium.webdriver.common.by import By # 实例化驱动对象 driver=webdriver.Chrome() def get_color(loc): color=driver.find_element(By.CSS_SELECTOR,loc).value_of_css_property('color') return color def open_brower(url,loc): # 打开网址 driver.get(url) # 获取颜色 c=get_color(loc) print(f"颜色是:{c}") # 退出 driver.quit() if __name__ == '__main__': u="https://www.baidu.com" loc="input#su" open_brower(u,loc)