How do I view CSS styles that apply to an HTML element in watir-webdriver?
Asked Answered
B

1

6

I am using watir-webdriver and am attempting to check the background-color of an HTML element. The problem is that the background-color is set in the CSS and not inside the HTML tag.

Is there a way to read the CSS value using watir-webdriver?

Brainwork answered 23/1, 2012 at 23:12 Comment(1)
I do not believe this capability exists because how the color was already decided upon is processed in the app server, web server, or browser engine. Expecting a test tool to show you what happened is to require a tool that will reverse engineer the web page source.Crosstree
C
7

Yes, use the style method

Example:

require 'watir-webdriver'
b = Watir::Browser.start 'minesweeper.github.com'
puts b.div(:id => 'g1minesRemaining100s').style 'background-image'
Cessionary answered 28/1, 2012 at 12:2 Comment(2)
Thanks. That worked. Is there any documentation that would of led me to this? Calling the style method with no parameters doesn't return this information and the API docs I refer to don't go into detail for this method.Brainwork
mmmm. I'm not sure. I have raised a bug to return style info when passing no parameters: github.com/watir/watir-webdriver/issues/120Cessionary

© 2022 - 2024 — McMap. All rights reserved.