How to click the hyperlink using Selenium Java

asked 1 year ago

Selenium web driver provides a locator, link text, and partial link text for a hyperlink to do the action. If the anchor tag "a" has the text then using the link text method the click can be performed. And if the text is partially static and partially dynamic then using partial link text the click can be performed. Also, we can perform the click by using other locators (Css, Xpath, Id, Name, Classname) Navigate to https://www.qafeast.com/demo,click on the Hyperlink tab.

hyperlink_selenium_java

 

Using Link Text

driver.findElement(By.linkText("Web browser automation")).click();
 

Using Partial Link Text

driver.findElement(By.partialLinkText("Web browser au")).click();
 

Using Other Locators

driver.findElement(By.xpath("//a[text()='Web browser automation']")).click();

 

 

Categories