我有一个链接:
<a class="title">My link</a>
它使用此CSS代码进行样式设置:
a.title {
color: #CC3333;
}
Run Code Online (Sandbox Code Playgroud)
如何验证"我的链接"文本是否为红色?我可以找到元素css=a.title,但是如何color == "#CC3333"在Selenium IDE中断言?
style.color如果实际 DOM 元素具有属性,将返回颜色style。在您的情况下,当标签中定义颜色时,<style>它将不起作用。这个我们需要你用getComputedStyle()。尽管如此,仍以 RGB 格式返回颜色,但您可以手动color转换颜色并验证 RGB 结果。
像这样:
assertEval(
"window.document.defaultView.getComputedStyle(window.document.getElementsByClassName('title')[0]).getPropertyValue('color')",
"rgb(204, 51, 51)"
)
Run Code Online (Sandbox Code Playgroud)
NB 还建议使用selenium.browserbot.getCurrentWindow()而不是window. 我离开了窗口以使片段更短。
| 归档时间: |
|
| 查看次数: |
8069 次 |
| 最近记录: |