您需要考虑以下两个事实:
WebDriverWait()
对 100 不应该是一个实时的服务员。考虑根据 测试规范 降低它。例如,将其设置为10秒:WebDriverWait wait = new WebDriverWait(driver, 10);
展望未来,你正在调用
click()
的方法,从而代替 ExpectedConditions 的visibilityOfElementLocated()
方法使用elementToBeClickable()
方法如下:WebElement response = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@]")));优化您的 xpath( 包括中的 tagName )
By.xpath("//tagName[@]")。举个例子 :By.xpath("//a[@]")优化您的代码以
click()
通过 WebDriverWait 返回元素时立即调用,如下所示:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@]"))).click();



