Locating strategy by Class name

Class Name is the attribute of the HTML tag. This is generally noted by .(dot). You can locate web element by searching the class name. See the below syntax for Locating strategy for Class Name.


driver.findElement(By.className(“Name of the Class”))

Scenario with Example:

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver;   
public class Locator_By_ID {   
public static void main(String[] args) 
WebDriver driver= new ChromeDriver() ; 
login_button= driver.findElement(By.className("Name of the Class"))

Leave a Reply

Your email address will not be published. Required fields are marked *