-1
我嘗試使用下面的代碼來獲取所有從下拉菜單中的元素:硒的webdriver findelements能夠gettext的元素,但不能點擊
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();
所以,我能夠打印鏈接文本使用for循環,但我無法點擊元素,拋出以下錯誤:
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
有沒有在解決這個錯誤的任何幫助?
你在UI中檢查了這個元素嗎?它是可見的還是隱藏的? –
你可能會看看[這篇文章](https://stackoverflow.com/questions/6101461/how-to-force-selenium-webdriver-to-click-on-element-which-is-not-currently- visib)對於可見元素的相同問題 –
它是UI中的一個可見元素,我可以使用for循環獲取下拉菜單中所有鏈接的文本。我無法點擊它 – Sunny