在下面的代码我需要打印color在Hex 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)