以前审查过有关此问题的帖子,但问题仍然存在。 http://preview.harriscountyfws.org/是一个公共站点,属于这个问题。Selenium Webdriver使用Java的ElementNotVisibleException
我试图点击一个下拉菜单并从Rainfall下拉列表中选择“Channel Status”。
我得到以下错误:
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not visible: Element is not currently visible and may not be manipulated
我附上的代码截图,但你也可以访问该网站,按F12
看代码。
这里是我的基础上,研究当前的代码到目前为止,我已经做了:
Select dropdown = new Select(driver.findElement(By.id("siteType")));
WebElement triggerDropDown = driver.findElement(By.className("k-i-arrow-s"));
triggerDropDown.click();
dropdown.selectByVisibleText("Channel Status");
dropdown.selectByIndex(1);
显示工作(dropdown.select ...) 两种结果ElementNotVisibleException
最后两个代码语句都不是。
这是不正确的,因为通过按triggerDropDown.Click()
,选择是可见的!
更好。我会一直等到我接受答案,因为其他人可能会回复,我想看看我们都可以了解这一点。我的怀疑,我可能是错误的,也许屏幕分为面板,你必须以某种方式选择一个或另一个面板,以便能够使该面板中的组件“可见” –
JeffC。在你的第二行,你会说“driver.findElement(By.cssSelector(”span.k-widget.kdropdown.k-header“))。click。它只是找到第一个出现的地方?现在我已经准备好从当前选项卡中选择“最后X次降雨”下拉菜单中的某个东西,但我遇到了问题,因为其周围的元素也被命名为“span.k-widget.kdropdown.k-header”。所以这是一个挑战。如果它是基于找到该文本的第一次出现,那么再次,它不是最佳代码。 –
是的,它找到了第一个。如果您需要选择除第一个之外的其他内容,则必须更改选择器。 – JeffC