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