2016-07-27 231 views
1

有沒有一種方法來獲取硒元素在機器人框架中的背景顏色?我用GET屬性嘗試,但它不會工作,在這裏返回None元素在硒/機器人框架中的背景顏色

是HTML

<li pl-repeat="(slideId, slideContents) in slides" pl-click="viewSlide(slideContents['w-l'].url, slideId)" pl-class="{checked : slideId == viewSlideKey}" class="pl-scope checked"><span class="pl-binding">Draft</span></li> 
+0

你能分享你的HTML? –

回答

2

您可以使用JavaScript return document.defaultView.getComputedStyle(document.getElementByID("ID"),null)['background-color']

,如果它是那麼一類同樣的事情做但document.getElementsByClassName("class-name")[0],null)['background-color']

+0

工作。謝謝 –

3

雖然您可以使用JavaScript來獲取計算風格,但我相信獲取樣式的慣用方式是使用Selenium的API。一旦您使用Get Webelement獲得webelement參考,您可以使用value_of_css_property方法獲取背景顏色。

Open Browser https://www.stackoverflow.com gc 
${elem} Get Webelement css=.post-tag 
${bg color} Call Method ${elem} value_of_css_property background-color 

結果:$ {背景顏色} = RGBA(225,236,244,1)

一個區別我注意到這裏在本試驗中是value_of_css_property返回的RGBA值而的getComputedStyle只返回rgb。

Selenium2LibraryExtension試圖通過執行Element Background Color Should Be來簡化操作。 value_of_css_property也在那裏使用。