我正在尝试使用我正在使用的 Selenium 进行黑盒测试:
- Mac 操作系统:版本:10.9.4
- java.版本:1.6.0_65
- 浏览器:firefox 版本 32.0.3
- Selenium :版本 2.43.0
页面包含一个表,每一行都有一个唯一的ID,该ID被正确提取并存储在String itemId
中
然后我创建相应的 WebElement
并尝试单击它,如下所示:
WebElement anchor = webDriver.findElement(By.id(itemId));
if (anchor != null) {
anchor.click();
Sleeper.sleep(2);
}
我遇到了这个异常:
WARNING: Error extracting item data
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
我读过几个关于 WebDriverWait
的问题,并尝试了以下代码:
String itemId = item.getAttribute("id");
WebDriverWait wait = new WebDriverWait(webDriver, 10);
WebElement anchor = wait.until(ExpectedConditions.elementToBeClickable(By.id(itemId)));
anchor.click();
Sleeper.sleep(2); // yes I know I waited 10 seconds already I have time :)
现在我得到以下异常:
WARNING: Error extracting item data
org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for element to be clickable
我尝试使用 ElementIsVisible
代替 elementToBeClickable,但它似乎已贬值
最佳答案
注意:此解决方案并不适用于出现类似错误的所有地方,但根据我的经验,这是 Web 应用程序上的常见问题。
如果您正在处理不可见的克隆表,您可以使用直接 xpath 到可见表或使用 findByELements 并在列表上迭代。
List<WebElement> temp_list = driver.findElements(By.id(itemId));
temp_list[1].click(); //example number, you have to find index corresponding to your element
请注意,只有当您有多个具有相同定位器的元素时,它才会起作用。您可以检查列表的大小。
temp_list.size();
关于java - org.openqa.selenium.ElementNotVisibleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26424146/