Name locator is also an effective way to locate an element in Selenium. It is similar way locating elements as that of ID locator. These are not unique on DOM. If there are multiple elements present with the same Name locator in the DOM then the first element on the page is selected while locating with below methods.And if there is no DOM element available with the given Name, then NoSuchElementException is raised in that case.


Syntax: WebElement element = driver.findElement(<NAME>));


Let’s take an example by locating “side menu” in “” page.

Step1: Open in browser

Step2: Hover your mouse to Forms present in side-menu

Step3: Right click on the mouse and do inspect element

Name Locator Example

element = driver.findElement("side-menu-form"));