如何解决我们可以用实际字词代替Hex / rgba2555,0,0,1将Web元素颜色和背景颜色打印为红色或蓝色吗
我正在使用硒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 举报,一经查实,本站将立刻删除。