Friday, September 13, 2019

How to get Text color using selenium | Selenium Automation




How to get Text color using selenium 



During testing many times we need to check whether element is displayed in the specific color or not like Header is displayed in Blue or not and Button is displayed in Red or not.

In Selenium using  getCssValue() method we can get the specific property and we can check text is displayed in red color or not.

In this post, I will check “How to check element in Enabled or not:” text color.

 

 

 

For blue : rgb(0, 111, 204) should be displayed

Complete Code for getting text color using selenium:
package practise;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class GetElementColor {
   
    static WebDriver driver;

    public static void main(String args[]) throws InterruptedException {
        //System.setProperty("webdriver.chrome.driver", "‎⁨path");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.get("https://mahantesh-hadimani.blogspot.com/2019/09/how-to-check-element-in-enabled-or-not.html");
        Thread.sleep(5000);
        WebElement text = driver.findElement(By.xpath("//a[contains(.,'How to check element in Enabled or not:')]"));
       
       
        //Read font-color property and print It In console.
          String fontColor = text.getCssValue("color");
          System.out.println("Font color -> "+fontColor);
         
    }

}




Console Output:



No comments:

Post a Comment

If any suggestions or issue, please provide