Locating strategy by Link Text

Another important locating strategy of selenium is Link Text. See the below code.

Example:

driver.findElement(By.linkText(“Link of the element”))

By this method you can search an element of the webpage by searching its Link Text. This is intended to select links only and anchor element. One of the major advantages of this locator is this is very useful when you are working with navigation Testing. But you have to know the text of the link before starting testing, which is the disadvantage of Link Text Locator.

Scenario with Example:

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver;   
public class Locator_By_ID {   
public static void main(String[] args) 
{ 
WebDriver driver= new ChromeDriver() ; 
driver.manage().window().maximize(); 
driver.get("https://www.testinglpoint.com"); 
 
login_button= driver.findElement(By.linkText("Link of the element"))
}

Leave a Reply

Your email address will not be published. Required fields are marked *