How to use webdriver selenium to get the value of the “style” element

I want to check whether the value of a style element is greater than a specific value (that is, is it > 666px?), But I can't get that value

Here is the HTML code for the style I want to capture:

<pre><span id="da2c" style="left: 666px; top: 27px;"></pre>

I'm trying to print its value using this code, but it doesn't print:

System.out.print(driver.findElement(By.id("da1c")).findElement(By.cssSelector("span")).getAttribute("style"));

I want something like this:

if ((driver.findElement(By.id("da1c")).findElement(By.cssSelector("span")).getAttribute("style")).value> 700) {
  System.out.println("value exceeding")
}

Solution

You can capture the calculated CSS value, as shown in the screenshot of firebug below:

like this:

WebDriver web = new FirefoxDriver(;
String visibility = web.findElement(By.xpath("//your xpath")).getCssValue("display");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>