相关疑难解决方法(0)

Selenium WebDriver中以十六进制格式的getCssValue(Color)

在下面的代码我需要打印colorHex format.

First Print语句以RGB格式显示值rgb(102,102,102).

第二个语句显示值在Hex 其中#666666

但是我手动将值输入到第二个print语句中102,102,102.

有没有办法将我从第一个语句(Color)获得的值传递给第二个print语句并获得结果?

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Google {

    public static void main(String[] args) throws Exception {

        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com/");
        String Color = driver.findElement(By.xpath("//div[@class='gb_e gb_f gb_g gb_xb']/a")).getCssValue("color");
        System.out.println(Color);
        String hex = String.format("#%02x%02x%02x", 102,102,102);
        System.out.println(hex);
    }
}
Run Code Online (Sandbox Code Playgroud)

java selenium selenium-webdriver

8
推荐指数
3
解决办法
3万
查看次数

标签 统计

java ×1

selenium ×1

selenium-webdriver ×1