< 1 minute read

Here is how to click a link by text with Selenium WebDriver in Java using the built in WebDriver helper methods or by XPath:

LoadFocus allows to easily set up checks to validate responses, status codes, response times, and receive instant alerts when issues arise. Monitor API performance and availability from over 26 cloud locations worldwide!

Start for free No credit card upfront.

Click link by full text using Selenium WebDriver


WebElement linkByText = driver.findElement(By.linkText("My Link"));
linkByText.click();

Click link by partial text using Selenium WebDriver


WebElement linkByPartialText = driver.findElement(By.partialLinkText("First"))
linkByPartialText.click();

Click link by text using XPath in Selenium WebDriver


WebElement linkByTextUsingXPath = driver.findElement(By.xpath("//a[text()='First']"));
linkByTextUsingXPath.click();

Click link by partial text using XPath in Selenium WebDriver


WebElement linkByPartialTextUsingXPath = driver.findElement(By.xpath("//a[contains(text(),'ABC')]"));
linkByPartialTextUsingXPath.click();

More details here on how to locate elements with Selenium WebDriver.

 

LoadFocus is a cloud testing platform for:

How fast is your website? Free Website Speed Test