LinkText

Any hyperlinks on a web page can be identified using linkText. It can be determined with the help of an anchor tag (<a>). But this must be made sure that there is only one unique link on the web page. If there are multiple links with the same link text (for example repeated header and footer menu) then Selenium will perform action on the first matching element with link. 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.linkText(<LINKTEXT>)); 

 

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

Step1: Open http://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

LinkText Locator Example

WebElement element = driver.findElement(By.linkText("Forms"));