TagName Locator

TagName locator is used to finding the elements which are matching with the specified Tag Name. It is mainly used with Group elements like, Select, check-boxes / dropdowns. 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.tagName(<TAGNAME>));

 

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

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

Step2: Hover your mouse to searchbutton present besides search box.

Step3: Right click on the mouse and do inspect element

TagName Locator Example

WebElement element = driver.findElement(By.tagName("button"));