开发者

How to select background color in selenium

开发者 https://www.devze.com 2023-04-07 23:43 出处:网络
can any budy explain how to select background color from <div class=\"shc\" style=\"background-color:#814c1b;\">About Me</div>

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号