【发布时间】:2015-07-14 13:12:31
【问题描述】:
我使用 Java 中的 Selenium 2.45.0。我的 Facebook 页面有问题。当页面加载这么久时,程序在 20 秒后停止并中断程序。
程序在查找 elementToBeClickable 时出现问题,这是最终工作程序。
我使用了很多命令: driver.manage().timeouts().pageLoadTimeout(5000, TimeUnit.MILLISECONDS); // 这不起作用
Set<String> winSet = driver.getWindowHandles();
List<String> winList = new ArrayList<String>(winSet);
String newTab = winList.get(winList.size() - 1);
driver.switchTo().window(newTab);
sleep(1500);
try {
driver.manage().timeouts().pageLoadTimeout(5000, TimeUnit.MILLISECONDS);
try {
driver.findElement(By.xpath("//span[@id='pagesHeaderLikeButton']/button")).click();
} catch (Exception e) {
System.out.println("This is not exist");
}
} catch(Exception e) {
System.out.println("no page");
System.out.println(e);
}
//当页面加载并在20秒后自动关闭时,不存在异常并且程序有刹车。
Thread.sleep(3000);
try {
driver.close();
} catch (Exception e) {
System.out.println("i cant close facebook");
}
// Allow time for the Like action to go through
sleep(1000);
// Close this window and switch back to the main one
try {
driver.switchTo().window(windowHandle);
}
catch(Exception e) {
System.out.println("cant back to main window");
}
这段代码有什么问题? 这不是所有的代码,而只是代码的元素。 我使用while和其他东西。 我的代码的这一刻有问题。
【问题讨论】: