How to select background color in selenium

Question:

can any budy explain how to select background color from

<div class="shc" style="background-color:#814c1b;">About Me</div>

in selenium.
i’ve source code like this

<div class="gwt-Label mock-tab selected-tab">My Account</div>

and i need to select color from it.
i’m using firebug to get xpath or css.

i’m using python and i’m new to selenium. please help.

Asked By: Sirga

||

Answers:

In Javascript:

var xx = document.getElementsByClassName("gwt-Label");
var bgColorIs = xx[0].style.backgroundColor

With CSS Selectors

div.gwt-Label.mock-tab.selected-tab.background-color

XPath:

[div@class=’gwt-Label mock-tab selected-tab’]

XPath samples

CSS Selectors by Class

Javascript – getting an element by class name or tag name

Answered By: Michael

This is the answer which i finally got for all color, font size and alignment related questions. Thx for all who tried to help.

sel.get_eval("el = this.browserbot.findElement('xpath or css'); bold
=window.document.defaultView.getComputedStyle(el,null).getPropertyValue('font-weight');")
Answered By: Sirga

You can use value_of_css_property on the element after you find it. Something like:

current_element = sel.find_element(By.CSS_SELECTOR, 'div.shc')
background_color = current_element.value_of_css_property('background-color')
Answered By: Cynic
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.