Reading CSS properties using Watir-WebDriver

There was recently a question on Stack Overflow about how you read a CSS property of an element that is defined in a stylesheet using Watir-WebDriver.

It’s really quite simple:

require 'watir-webdriver'
b = Watir::Browser.start 'minesweeper.github.com'
puts b.div(:id => 'g1minesRemaining100s').style 'background-image'

2 thoughts on “Reading CSS properties using Watir-WebDriver

  1. It is great to use style attribute to verify an element’s style. However, I just found an annoying issue. Different browsers may return slightly different values.
    For example, for the same element,
    Firefox and IE return the color style like ‘rgba(51,51,51,1)’
    Chrome returns the color style like ‘rgb(51, 51, 51)’
    I have to add some very ugly browser type check logic in my library or step definition. :-(

    Does anybody have an idea to handle this issue?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s