getCSSValue method is used to validate the CSS values and properties on the webpage such as color, background color, font-family, etc., CSS code helps to ornaments of the webpage.
String value will be the input parameter and it will return the property value of the Cascade Style Sheet.
JAVA API Syntax : java.lang.String getCssValue(java.lang.String propertyName)
Code:
String value will be the input parameter and it will return the property value of the Cascade Style Sheet.
JAVA API Syntax : java.lang.String getCssValue(java.lang.String propertyName)
Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.*;
public class getCssvalue {
private static WebDriver driver = null;
public static void main(String[] args){
//setting the property for chrome browser and to invoke the chrome browser
System.setProperty("webdriver.chrome.driver",
"C://Selenium//chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("http://www.yahoo.com");
//Retrieving CSS value for search submit button on yahoo page
WebElement Ysearch = driver.findElement(By.id("search-submit"));
//Printing the result into the console // Input parameter passed for font-family
System.out.println(Ysearch.getCssValue("font-family"));
//Retrieving CSS value for Yahoo logo color
WebElement Ycolor = driver.findElement(By.id("yucs-logo-ani"));
//Printing the result into the console // Input parameter passed for color
System.out.println(Ycolor.getCssValue("color"));
}
}
Output:rgba(50, 79, 225, 1)