问题
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