我使用 Selenium 和 Java 编写了一个脚本。它有时工作正常,没有任何异常。但有时我会收到 TimeOutException,因为我使用了显式等待。这种行为是否与应用程序有关?可能是什么问题呢?
ChromeOptions options = new ChromeOptions();
options.addArguments("incognito");
WebDriver driver = new ChromeDriver(options);
driver.get("url");
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.id("usernameid")));
driver.findElement(By.id("usernameid")).sendKeys("632145");
wait.until(ExpectedConditions.elementToBeClickable(By.id("passwordid")));
driver.findElement(By.id("passwordid")).sendKeys("1234");
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//button[@type='button']")));
driver.findElement(By.xpath(".//button[@type='button']")).click();
脚本有时在按钮处失败。我收到超时异常。