簡體   English   中英

Python 使用 selenium webdriver 獲取元素的 CSS 顏色值

[英]Python obtain CSS color value of element using selenium webdriver

我試圖從類中的圖像獲取背景顏色,問題是它給了我一個錯誤“無效的選擇器:不允許復合類名”。

我嘗試了很多版本來獲取顏色(rgb),每次出現錯誤時,我已經很困惑,因為我知道有幾種方法可以做到,但我無法完成任何一種。

HTML代碼:

<div class="reaction-time-test view-splash" ng-class="&quot;view-&quot; + test.getView()" ng-fast-click="test.clickedBg()">

代碼:

.reaction-time-test.view-splash {
background: #2b87d1;
}

我嘗試過的(我的最后一次嘗試)- ofc Python

check = driver.find_element_by_class_name(".reaction-time-test.view-splash").value_of_css_property('background')

也試過:

check = driver.find_element_by_css_selector(".reaction-time-test.view-splash") # since it only has one element in the css

首先,我找到了顏色所在的類,然后我嘗試獲取該類中名為“背景”的唯一元素的值

嘗試 xpath = //div[@class='reaction-time-test view-splash']

java中的例子

String backColor=driver.findElement(By.xpath("//div[@class='reaction-time-test view-splash']")).getCssValue("background");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM