访问 selenium 中的 css 类属性 [英] access css class properties in selenium
问题描述
我有一个 HTML <div>
元素并希望使用 Selenium 检查它是否左对齐.但是 float:left
CSS 属性是在 CSS 类中定义的.
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.
有什么方法可以通过 Selenium 访问 CSS 类属性?或者还有其他方法可以获得这个值吗?
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>
在sample.css中
In sample.css
.myclass{
float:left;
}
我试图使用 getEval()
- this.page().findElement("foo")
来找出获取 CSS 类属性的方法.
I was trying to use getEval()
- this.page().findElement("foo")
to find out a way to get CSS class attributes.
推荐答案
通过 webdriver 你可以使用 css 选择器:
With webdriver you can use css selektors:
WebElement element = driver.findElement(By.cssSelector(".myclass"));
String float = element.getCssValue("float");
请参阅 JavadocWebElement的
See Javadoc of WebElement
更新答案!
这篇关于访问 selenium 中的 css 类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!