How to select background color in selenium
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开发者_JAVA技巧-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.
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');")
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')
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
精彩评论