ClassName

ClassName locator helps in locating element through the class attribute in Selenium.  These are also not unique on DOM. And if there is no DOM element available with the given className, then NoSuchElementException is raised in that case.

 

Syntax: WebElement element = driver.findElement(By.className(<CLASSNAME>));

 

Let’s take an example by locating “side menu” in “https://demoapp1.tequality.tech/” page.

Step1: Open https://demoapp1.tequality.tech/” in browser

Step2: Hover your mouse to side-menu

Step3: Right click on the mouse and do inspect element

ClassName Locator Example


WebElement
element = driver.findElement(By.className("nav"));