我想在表格中验证特定值的颜色编码背景。颜色代码是背景颜色:rgb(96,192,96)。我在页面上有5个不同的链接。每个链接具有相同的背景颜色。我需要验证天气背景颜色显示为每个链接的rgb(96,192,96)。如果颜色代码是rgb(96,192,96)以外的任何其他代码,则代码应该认为链接/服务器已关闭。
页面上显示的五个值/链接是Ssi-1-a,Ssi-2-a,Ssi-3-a,Ssi-4-a和Ssi-5-a
如何使用Xpath或任何其他方法验证?提供下面的代码
<html>
<head>
<body>
<b>Status as of </b>
Wed Oct 25 16:57:57 2017
<br/>
<br/>
This page shows the current version and build date of the SSI code loaded into the JVMs that constitute the environment
you selected.
<br/>
<br/>
<br/>
<div style="float:left">
<table style="display:inline-table" width="500" border="1">
<tbody>
<tr>
<tr>
<tr>
<th>Prod</th>
<td style="background-color:rgb(96,192,96)" align="center">
<a href="https://XXXXXXXXXXXXXX-XXX.net:XXXXXX/ssiadmin/">Ssi-1-a</a>
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</div>
</body>
</html>
答案 0 :(得分:2)
driver.findElement(By.name("nameOfComponent")).getCssValue("background-color");
答案 1 :(得分:0)
您可以使用WebElement的getAttribute方法来分析style属性的值。以下代码应该让您大致了解如何执行此操作:
WebElement linkToCheck = driver.findElement(By.xpath("xpathOfTheLink"));
if(!linkToCheck.getAttribute("style").contains("rgb(96,192,96)")){
// server is down, --> does some action
}
其中xpathOfTheLink
是您要检查的链接的xpath。假设您有5个不同的链接,则必须创建5个xpath,或者使用动态xpath,允许您使用上面的代码检查循环中的每个xpath。
&#34;风格&#34;属性最好转换为带有尾部分号的文本表示。
因此,您可能需要检查它是否包含除&#34; rgb(96,192,96)&#34;以外的其他内容。我让你尝试,或提供给定html的网址,所以我可以尝试(我很想看到结果)。