断言伪代码的css颜色

时间:2016-01-25 09:10:57

标签: java css eclipse selenium

对于网站,我必须断言使用颜色。该元素很容易找到但我似乎无法弄清楚如何断言颜色,因为css使用伪代码来生成显示的颜色。我使用以下内容来获取元素并检索颜色:

assertEquals("rgba(236, 117, 4 , 1)", driver.findElement(By.xpath("//*[@class='ab-toggle']")).getCssValue("color"));

页面上的代码是:

<div class="ab-toggle">::before</div> //in chrome
<div class="ab-toggle"></div> //in firebug

css:

.contenthere .ab-toggle::before {
color: #ec7504;
content: "▾";
display: inline-block;
font-family: "icons";
font-size: 1.6em;
line-height: 1;
margin-left: 0.3em;
vertical-align: middle;
}

如果我运行我的代码,它会返回一个comparisonFailure:

org.junit.ComparisonFailure: expected:<[rgba(236, 117, 4 , 1)]> but was:<[rgba(34, 34, 34, 1)]>

我也可以在CSS中看到这种颜色,但不知道如何从断言语句中获取正确的颜色

 .contenthere a.expandable-toggle {
color: #222;
cursor: pointer;

当我使用以下内容时,我还尝试使用css选择器而不是xpath来访问元素:

assertEquals("rgba(236, 117, 4 , 1)", driver.findElement(By.cssSelector("div.ab-toggle ::before")).getCssValue("color"));

导致NoSuchElementException。当我尝试:

assertEquals("rgba(236, 117, 4 , 1)", driver.findElement(By.cssSelector("div.ab-toggle")).getCssValue("color"));

它只返回旧结果,就像我使用xpath定位元素

时一样

0 个答案:

没有答案