get CSS Property values using selenium

2019-06-13 08:05发布

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条回答
\"骚年 ilove
2楼-- · 2019-06-13 08:19

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.

查看更多
登录 后发表回答