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.
To click a link, we can use the link text locator which matches the text enclosed within the anchor tag. We can also use the partial link text locator which matches the text enclosed within the anchor tag partially. NoSuchElementException is thrown if there is no matching element found by both these locators.
We can get an attribute value from a href link in Selenium. To begin with, we have to first identify the element having an anchor tag with the help of any of the locators like css, id, class, and so on. Next, we shall use the getAttribute method and pass href as a parameter to the method.
webDriver. findElement(By. xpath("//a[@href='/docs/configuration']")). click();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With