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(By.name(<NAME>));
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 Forms present in side-menu
Step3: Right click on the mouse and do inspect element
WebElement element = driver.findElement(By.name("side-menu-form"));