Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I have an 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 the page is completely loaded. Can anyone help with this?

2 Answers

0 votes
by (62.9k points)

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

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

If the element is not visible please scroll down the page then perform click the action

If you wish to Learn Selenium visit this Selenium Webdriver Tutorial and Selenium Webdriver Interview Questions by Intellipaat.

To learn in-depth about Selenium, sign up for an industry based Selenium course.

0 votes
by (1.1k points)

Option 1: Utilize the Action Class to Click and Navigate

In certain situations, it may be necessary to use the Actions class to interact with the element to avoid visibility issues.

import org.openqa.selenium.interactions.Actions;

WebElement targetElement= driver.findElement(By.xpath("//a[text()='App Configuration']"));

Actions actionBuilder = new Actions(driver);

actionBuilder.moveToElement(targetElement).click().perform();

Solution 2: Execute Wait Commands for ElementToBeClickable

The placement of an explicit wait to ensure that a certain element is clickable could mitigate the problem especially in situations where timing delays and or overlay issues exist.

import org.openqa.selenium.support.ui.WebDriverWait;

import org.openqa.selenium.support.ui.ExpectedConditions;

import java.time.Duration;

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='App Configuration']")));

element.click();

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...