How to click a href link using Selenium

Psl picture Psl · Jun 4, 2015 · Viewed 192.1k times · Source

I have a html href link

<a href="/docs/configuration">App Configuration</a>

using Selenium I need to click the link. Currently, I am using below code -

Driver.findElement(By.xpath("//a[text()='App Configuration']")).click(); 

But it's not redirecting to the page. I also tried below code -

Driver.findElement(By.xpath(//a[@href ='/docs/configuration']")).click();

But this is throwing below exception -

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 13 milliseconds

The link is visible and page is completely loaded. I don't know what's wrong with my code.

Answer

Saritha G picture Saritha G · Jun 4, 2015
 webDriver.findElement(By.xpath("//a[@href='/docs/configuration']")).click();

The above line works fine. Please remove the space after href.

Is that element is visible in the page, if the element is not visible please scroll down the page then perform click action.