Selenium webdriver 使用wait.until(ExpectedConditions.visibilityOf(element)方法获取异常

Selenium webdriver 使用wait.until(ExpectedConditions.visibilityOf(element)方法获取异常,selenium-webdriver,selenium-chromedriver,Selenium Webdriver,Selenium Chromedriver,我正在尝试为selenium使用chrome驱动程序。当所有其他操作都正常工作时,当我使用下面的代码时,我会遇到异常。元素确实存在,并且驱动程序不为null。如果我注释掉this调用(并替换为sleep),测试将正常运行。知道失败的原因是什么吗 WebDriverWait wait = new WebDriverWait(driver, timeout); wait.until(ExpectedConditions.visibilityOf(element)); java.lang.Null

我正在尝试为selenium使用chrome驱动程序。当所有其他操作都正常工作时,当我使用下面的代码时,我会遇到异常。元素确实存在,并且驱动程序不为null。如果我注释掉this调用(并替换为sleep),测试将正常运行。知道失败的原因是什么吗

WebDriverWait wait = new WebDriverWait(driver, timeout);
 wait.until(ExpectedConditions.visibilityOf(element));
java.lang.NullPointerException 在org.openqa.selenium.remote.RemoteWebElement.isDisplayed上(RemoteWebElement.java:320) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中 位于java.lang.reflect.Method.invoke(Method.java:498) 位于org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51) 在com.sun.proxy.$Proxy10.isDisplayed上显示(未知源) 位于org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:315) 位于org.openqa.selenium.support.ui.ExpectedConditions.access$100(ExpectedConditions.java:44) 位于org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:301) 位于org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:298) 位于org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:248)


将selenium降级到3.0.1解决了此问题。

此错误可能是由chromedriver引起的。我在chrome驱动程序版本77.x中遇到了相同的问题,然后在将chromedriver降级到版本76.x时问题得到了解决。请参阅以下页面:

您使用的是什么操作系统?您是否使用兼容版本的
chrome
chromedriver
(例如v77是最新版本)?我使用的是chrome 77和selenium 4.0.0-alpha-2。我还下载了chrome 77的支持chromedriver。我刚刚尝试将selenium降级到3.141,并得到了相同的异常。如果有任何提示,我将不胜感激。您能否提供(最低数量的)HTML复制行为?什么是
元素
以及它是如何修饰的?降级,尤其是到目前为止已经过时的版本,几乎从来都不是正确的解决方案。