My link It states this CSS code: a.title { color: #C...">

Selenium IDE: how to check text color using CSS

I have a link:

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

It states this CSS code:

a.title {
  color: #CC3333;
}

How can I check that the text “My Link” is red? I can find the element with css=a.title, but how can I claim that color == "#CC3333"in the Selenium IDE?

+5
source share
1 answer

style.colorwill return color if the actual DOM element has an attribute style. In your case, when the color is defined in the tag <style>, it will not work. For this you need to use getComputedStyle(). However, it colorreturns the color in RGB format, but you can convert the color manually and check the result of RGB.

Like this:

assertEval(
  "window.document.defaultView.getComputedStyle(window.document.getElementsByClassName('title')[0]).getPropertyValue('color')",
  "rgb(204, 51, 51)"
)

N.B. selenium.browserbot.getCurrentWindow() window. , .

+4

All Articles