2015-01-21 174 views
0

我有Web表格,其中綠色的行顏色表示有效的數據,紅色的行表示無效的數據。看到這個截圖:獲取網絡表格單元格的顏色

http://i.stack.imgur.com/wWqxM.jpg

我可以得到行和值的計數,但不知道如何讓表中的每一行的顏色。

以下是獲取行數和值的代碼。

boolean ispresent = foxdriver.findElements(By.xpath("//*[@id='ctl00_CP_gvI']/tbody/tr/td")).size()!=0; 
if (ispresent = true) { 
    List<WebElement> drup = foxdriver.findElements(By.xpath("//*[@id='ctl00_CP_gvI']/tbody/tr/td")); 
    int druplst = drup.size(); 
    System.out.println(druplst); 
    for (int x=2; x <= druplst; x++) { 
     String drupname = foxdriver.findElement(By.xpath("//*[@id='ctl00_CP_gvI']/tbody/tr["+x+"]/td[1]")).getText().trim(); 
     System.out.println(drupname); 
    } 
} 
+0

您需要提供構成表格的HTML示例。行顏色是否被硬編碼爲'style'屬性,還是通過CSS表格樣式應用於表格行和單元格中的'class'和/或'id'屬性? – Bobulous 2015-01-21 10:31:18

+0

其實它是一個gridview和顏色是在C#.net後端代碼,它是根據條件硬編碼。 – 2015-01-21 11:39:50

回答

1

可以實現RGBA背景色通常場景

對於例如值。此頁上,在代碼部分,U可以得到背景:

WebElement ele = driver.findElement(By.xpath("//pre")); 
System.out.println(ele.getCssValue("background-color")); 

這將爲您提供O/P - RGBA(238,238,238,1)這樣你就可以在你的情況下,實現同並通知字符串意義上紅色或綠色的區別。