如何使用Webdriver Selenium获取“样式”的值元件 [英] How to Using Webdriver Selenium to get the value of "style" element

查看:107
本文介绍了如何使用Webdriver Selenium获取“样式”的值元件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查样式元素的值是否大于特定值(即,是> 666px?),但我无法得到该值。

I want to check whether the value of a style element is greater than a particular value (i.e., is left > 666px ?), but I am unable to get ahold of the value.

以下是我要捕获的样式的HTML代码:

Here is the HTML code of the style that I want to capture:

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

我使用此代码尝试打印其值,但不打印:

I am using this code to try to print its value, but it's not printing:

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

我想要这样的东西:

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


推荐答案

您可以捕获Computed Css值,如下面的firebug屏幕截图所示:

You may capture the Computed Css value as shown in the firebug screenshot below:

这样:

WebDriver web = new FirefoxDriver(;
String visibility = web.findElement(By.xpath("//your xpath")).getCssValue("display");

这篇关于如何使用Webdriver Selenium获取“样式”的值元件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆