I am using a selenium JAVA code to print the color and background color. I am able to get RGBA and can convert to HEx..but is there a way i can actually print this color as RED ( which is what in the website) ...here is my example code..
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 ****************");
}
}