-1

I am trying to get all the elements from a dropdown menu using the following code:

List<WebElement> actmenu = driver.findElements(By.className("mbrMenuItems")); 
    for (int i = 0; i < actmenu.size(); i++) {
        System.out.println(actmenu.get(i).getText());
    }
    actmenu.get(0).click();
    actmenu.get(1).click();

So, I am able to print the link text using the for loop but I am not able to click on the elements, throws the following error:

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 30.31 seconds

any help in solving this error?

Sunny
  • 11
  • 1
  • 3
  • Did you check this element in the UI? is it visible or hidden? – TuyenNTA Jun 18 '17 at 02:25
  • You might have a look a [this post](https://stackoverflow.com/questions/6101461/how-to-force-selenium-webdriver-to-click-on-element-which-is-not-currently-visib) for the same problem with visible element – TuyenNTA Jun 18 '17 at 02:29
  • It is a visible element in UI, I am able to get the text of all the links in the drop down menu using the for loop. I am not able to click it – Sunny Jun 18 '17 at 03:31
  • Did you try to click by using java script like the post I proposed? – TuyenNTA Jun 18 '17 at 03:59
  • What line is the exception thrown on? What's the complete output of the program? What happens when the links are clicked? Does it leave the page or ? – JeffC Jun 18 '17 at 04:30
  • The exception is thrown on the line actmenu.get(0).click(); The output is just to go to that link. When the link is clicked it will open the link page. I just want to open the link page by clicking on the WebElement in the List – Sunny Jun 18 '17 at 06:20
  • Can you give us HTML code? – Murthi Jun 18 '17 at 07:11

1 Answers1

1

The method .getText() returns value from HTML source. Maybe the element you are trying to click is not yet rendered? Try to wait for an element

WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.visibilityOf(element);

The above code will wait 10 seconds until the element is visible.

Fenio
  • 3,528
  • 1
  • 13
  • 27