Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

How to click on a hyperlink using Selenium WebDriver?

You can click on a hyperlink using Selenium WebDriver in Java by calling the click() method of the WebElement interface. Here is an example:


// create a new instance of WebDriver
WebDriver driver = new ChromeDriver();

// navigate to a web page
driver.get("https://www.lambdatest.com");

// find the hyperlink using its link text
WebElement link = driver.findElement(By.linkText("Click here"));

// click on the hyperlink
link.click();

// wait for the new page to load
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.urlContains("new-page"));

// close the browser
driver.quit();

To click on a hyperlink using the WebDriver API, first, create an instance of WebDriver and navigate to a web page. Then find the hyperlink using its link text, "Click here," in this case, and store it in a WebElement variable called a `link`. Finally, use the `click()` method to click on the hyperlink and wait for it to load by using a `WebDriverWait` object. Once this is done, close the browser using `quit()`.

LambdaTest

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing
LambdaTest

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More
LambdaTest

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS

Support

24/7 support

Security

Enterprise grade security

Cloud

Fastest test execution cloud