How to Using Webdriver Selenium to get the value of “style” element

后端 未结 3 1975
醉酒成梦
醉酒成梦 2020-12-06 02:32

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.

Here is

相关标签:
3条回答
  • 2020-12-06 02:58

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

    enter image description here

    like this:

    WebDriver web = new FirefoxDriver(;
    String visibility = web.findElement(By.xpath("//your xpath")).getCssValue("display");
    
    0 讨论(0)
  • 2020-12-06 03:01

    If you execute .getAttribute("style") on that span, you will recieve a String.

    left: 666px; top: 27px;
    You can use string manipulation to fetch a particular style.

    Alternatively, you can execute some javascript magic using the JavaScriptExecutor, and fetching the left value directly by

    String script = "var thing = window.document.getElementById('da2c'); 
                                 window.document.defaultView.getComputedStyle(thing, null).getPropertyValue('left');";
    

    and then check it from there.

    0 讨论(0)
  • 2020-12-06 03:02
    driver.findElement(By.locator( yourLocator )).getAttribute( requiredAttribute )
    

    It will return String

    0 讨论(0)
提交回复
热议问题