getCssValue (Color) in Hex format in Selenium WebDriver

前端 未结 4 1917
遥遥无期
遥遥无期 2020-12-19 03:03

In the following code I need to print the color in Hex format.

First Print statement is showing value in RGB format

4条回答
  •  青春惊慌失措
    2020-12-19 03:28

    The code works, but just a little typo. The Color.fromString would be upper case C

    import org.openqa.selenium.support.Color;
    
    String color = driver.findElement(By.xpath("xpath_value")).getCssValue("color");
    System.out.println(color);
    String hex = Color.fromString(color).asHex();
    System.out.println(hex);
    

提交回复
热议问题