access css class properties in selenium

﹥>﹥吖頭↗ 提交于 2020-01-13 04:36:06

问题


I have a HTML <div> element and wish to check if it is left aligned using Selenium. However the float:left CSS property is defined in a CSS class.

Is there any way in which I can access the CSS class attributes through Selenium? Alternately is there any other way to get this value?

<div class="myclass">
...
</div>

In sample.css

.myclass{
   float:left;
}

I was trying to use getEval() - this.page().findElement("foo") to find out a way to get CSS class attributes.


回答1:


With webdriver you can use css selektors:

WebElement element = driver.findElement(By.cssSelector(".myclass"));
String float = element.getCssValue("float");

See Javadoc of WebElement

Updated Answer!



来源:https://stackoverflow.com/questions/11826392/access-css-class-properties-in-selenium

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