0

I am trying to click on a close button to close a popup. However, I get the error element not visible. I am checking if the element exists in the page, but still the error comes up. The piece of code giving the error is

while(driver.findElements(By.className("ui_close_x")).size() < 0);
driver.findElements(By.className("ui_close_x")).get(0).click();
System.out.println("Clkd");

Where am I going wrong?

Trying to crawl tripAdvisor

2
  • Can you share your HTML code? Commented Dec 13, 2016 at 8:20
  • check the size of driver.findElements(By.className("ui_close_x")) - you can have more then one such element, and the first one (with index 0) can be not visible Commented Dec 13, 2016 at 8:25

1 Answer 1

1

Try to use explicit wait with expected conditions

WebDriverWait wait = new WebDriverWait(driver, 10);
List<WebElement> elements = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className("ui_close_x")));
elements.get(0).click();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. Worked perfectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.