How to get element color with Selenium

前端 未结 4 1815
走了就别回头了
走了就别回头了 2020-12-18 00:34

I want to check the color of an element in an html page. The color of this element is set with a javascript, look at the image

The element with div-id \"Ab_banco_M

4条回答
  •  一整个雨季
    2020-12-18 01:10

    Try below code

    public String ColorVerify(String cssSelector, String cssValue)
    {
        /* This method used to verify color code*/
        WebElement target = driver.findElement(By.cssSelector(cssSelector));
        String colorCode= target.getCssValue(cssValue);
        String hexacolor = Color.fromString(colorCode).asHex();
        return hexacolor;   
    }
    

提交回复
热议问题