问题描述
我正在使用硒JAVA代码打印颜色和背景色。我能够获得RGBA并可以转换为HEx ..但是有一种方法可以将这种颜色实际打印为RED(这是网站上的颜色)...这是我的示例代码。
public class FormElementsPractice {
WebDriver driver ;
@Before
public void setUp() throws Exception {
driver = utils.HelperFunctions2.createAppropriateDriver("Chrome");
driver.manage().window().maximize();
driver.get("http://www.seleniumframework.com/Practiceform/");
System.out.println("***************** Execution Started ****************");
}
@Test
public void FormPracticetest() throws InterruptedException {
String color = driver.findElement(By.id("colorVar")).getCssValue("color");
String BGcolor = driver.findElement(By.id("colorVar")).getCssValue("background-color");
System.out.println("Color is :"+ color);
String[] numbers = color.replace("rgba(","").replace(")","").split(",");
int r = Integer.parseInt(numbers[0].trim());
int g = Integer.parseInt(numbers[1].trim());
int b = Integer.parseInt(numbers[2].trim());
int a = Integer.parseInt(numbers[3].trim());
System.out.println("r: " +r +" "+ "g: " + " "+ g + "b: " + b + " " + "a :"+a);
String hex = "#" + Integer.toHexString(r) + Integer.toHexString(g) + Integer.toHexString(b) + Integer.toHexString(a);
System.out.println(hex);
System.out.println("Initial Color is :" + hex + "Background color is " + BGcolor);
Thread.sleep(6000);
String Changedcolor = driver.findElement(By.id("colorVar")).getAttribute("color");
System.out.println("Initial Color is :" + Changedcolor);
}
@After
public void tearDown() throws Exception {
System.out.println("****************** Execution End ****************");
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)