我有一个链接:
<a class="title">My link</a>
它使用以下CSS代码设置样式:
a.title {
color: #CC3333;
}如何验证文本"My link“是否为红色?我可以用css=a.title定位元素,但是如何在Selenium IDE中断言color == "#CC3333"呢?
发布于 2012-02-15 23:22:08
如果实际的DOM元素有style属性,style.color将返回color。在您的情况下,当在<style>标签中定义颜色时,它将不起作用。我们需要你使用getComputedStyle()。尽管如此,color仍以RGB格式返回颜色,但您可以转换颜色manually并验证RGB结果。
如下所示:
assertEval(
"window.document.defaultView.getComputedStyle(window.document.getElementsByClassName('title')[0]).getPropertyValue('color')",
"rgb(204, 51, 51)"
)注意:还建议使用selenium.browserbot.getCurrentWindow()而不是window。我离开窗口是为了让代码片段更短。
https://stackoverflow.com/questions/9291852
复制相似问题