Selenium IDE:如何使用CSS检查文本颜色

use*_*063 5 css ide selenium

我有一个链接:

<a class="title">My link</a>

它使用此CSS代码进行样式设置:

a.title {
  color: #CC3333;
}
Run Code Online (Sandbox Code Playgroud)

如何验证"我的链接"文本是否为红色?我可以找到元素css=a.title,但是如何color == "#CC3333"在Selenium IDE中断言?

p0d*_*eje 4

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. 我离开了窗口以使片段更短。