【发布时间】:2016-09-09 15:18:30
【问题描述】:
我遇到了 Selenium WebDriver 的一个非常奇怪的问题。登录网站后,我们的应用程序显示一个基本身份验证弹出窗口,我已通过 AutoIT 处理。问题是页面加载后,Selenium 需要大约 80-100 秒来执行下一个命令。下一个命令可以是任何东西,我只是想在页面加载后获取浏览器的标题。在 80-100 秒内执行下一个命令后,Selenium 以正常速度执行其余命令。
知道可能是什么问题吗?我在下面添加了我的代码。
driver.findElement(By.id("username").sendKeys("username");
driver.findElement(By.id("password").sendKeys("passowrd");
driver.findElement(By.id("submit").click();
File file = new File("lib", "jacob-1.17-x64.dll");
System.setProperty(LibraryLoader.JACOB_DLL_PATH,
file.getAbsolutePath());
AutoItX autoIt = new AutoItX();
Thread.sleep(2000);
String title = "Authentication Required";
autoIt.winActivate(title, "");
autoIt.winWaitActive(title);
if (autoIt.winExists(title)) {
autoIt.send("username{TAB}", false);
autoIt.send("password{Enter}", false);
}
} catch (InterruptedException ex) {
//
}*/
System.out.println(driver.getTitle());
System.out.println(driver.findElement(By.cssSelector(".sdfsdf")).getText());
System.out.println(driver.findElement(By.id("key")).getAttribute("placeholder"));
在上面的代码中,Selenium 需要大约 60-80 秒来执行 get Title 命令,但之后它就可以正常工作了。即使我改变了代码中命令的顺序,结果还是一样的。
【问题讨论】:
-
您使用的是最新的 selenium chrome 驱动程序版本吗?它可能已经过时了。在这 60-80 秒之后会发生什么,页面可能会刷新?也可能是,当您调用
driver.getTitle()时,该页面尚未加载。您应该添加一些wait条件或其他内容。 -
我使用的是 Firefox 浏览器,不,它在页面加载后等待 60-80 秒。