Friday, April 27, 2018

How to get the color code of dropdown text with Selenium WebDriver ?

How to get the color code of dropdown text with Selenium WebDriver ?

Solution :

Lets first create the instance of WebDriver :

WebDriver driver;
System.setProperty("webdriver.chrome.driver", "C:/Users/User/Downloads/chromedriver/chromedriver.exe");
driver = new ChromeDriver();


Next, we will open the url and find the WebElement i.e dropdown.

driver.get("file:///C:/Users/User/Desktop/Blog/ColorText.html");
WebElement dropDown = driver.findElement(By.cssSelector("select[class='selectDiv']"));
Now, create the instance of "Select" class and click on the option "Audi" from dropdown
by using "selectByVisibleText()" method.

Select select = new Select(dropDown);
select.selectByVisibleText("Audi");
Now, we will get the selected option color code and by using "Color" class of java we will convert the rgb color code to hex color code.

String colorValue = select.getFirstSelectedOption().getCssValue("color");
String hexColorCode = Color.fromString(colorValue).asHex();
System.out.println("Selected Option color code is " + hexColorCode );
Hope you like this post. Thanks

2 comments:

  1. Selenium IDE, or Selenium Integrated Development Environment is a handy software testing tool, prepared by Apache Software Foundation. Pronounced as the one of the fastest and easiest testing frameworks,
    Selenium Automation Training London

    ReplyDelete
  2. After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
    Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in


    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune

    ReplyDelete

Questions Asked in Interview for Manual Testing Engineer?

1. What is Boundary Value Analysis and Equivalence Partitioning ? 2. What is Responsive web design ? 3. What is Globalization Te...