Class name method is used to find the element by its CSS values. Developer is using the style attribute for using the class name to decorate the webpage.
CSS example:-
table {
CSS example:-
table {
border-collapse: collapse;
border-spacing: 0;
}
caption, th, td {
font-weight: normal;
text-align: left;
vertical-align: middle;
}
For example, the above CSS codes will be mapped into the Class names to inherit between CSS styles and Class name.import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class classname {
public static void main(String[] args){
//Launching firefox Browser
WebDriver driver = new FirefoxDriver();
//Launching facebook.com
driver.get("http://www.facebook.com");
//Getting the classname value and assigning it to variable
WebElement fClassName = driver.findElement(By.className("inputtext"));
//printing the result into the console
System.out.println(fClassName);
}
}
Output:
[[FirefoxDriver: firefox on WINDOWS (b3831c55-a574-4587-9317-157fe191938d)] -> class name: inputtext]