get CSS Property values using selenium

为君一笑 提交于 2019-12-23 05:19:42

问题


How to get the property value of a CSS class using selnium RC

I tried it using webdriver but can't get what is required


回答1:


You can use the getEval(String script) command to evaluate javascript to fetch the property.

Selenium can be pretty limited in this sense

EDIT:

this.style.someAttribute will give you the value of someAttribute css style for the given Selenium node.

Also, if you want to run JavaScript on elements within the document body, such as document.getElementById .., you need to preceed your JavaScript string with "this.browserbot.getCurrentWindow()". For example, if I wanted to get the innerHTML of the element with id 'page_title', I would call

String title = getEval("this.browserbot.getCurrentWindow().document.getElementById('page_title').innerHTML");

This will evaluate the JavaScript in the context of the window you are testing. Failure to include this will execute JavaScript within the context of the Selenium frame. See this documentation on the Selenium API.



来源:https://stackoverflow.com/questions/9578900/get-css-property-values-using-selenium

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!