MacOS + Java + Eclipse + Firefox + Webdriver。最新版本
public static void main(String args[]){
FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(profile);
// for testing only
driver.manage().timeouts().pageLoadTimeout(3,TimeUnit.MILLISECONDS);
try {
Thread.sleep(3000);
driver.get("http://www.google.com");
Thread.sleep(57000);
driver.close();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
最简单的代码。始终在行中阻止driver.get(" http://www.google.com");。抛出内部异常,catch不在此处工作。
超时在我的计划中是不可避免的。
如何完全取消该块?谷歌的结果显示了一个新的主题,这可能并不可靠。
Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out waiting for page load.
Command duration or timeout: 78 milliseconds
Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:30'
System info: host: '', ip: '', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.5', java.version: '1.7.0_25'
Session ID: c927ef07-0921-6b4e-afe6-113782ab7639
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true,
cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox,
handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true,
nativeEvents=false, rotatable=false, locationContextEnabled=true,
applicationCacheEnabled=true, takesScreenshot=true, version=30.0}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:304)
答案 0 :(得分:1)
更改此行:
driver.manage().timeouts().pageLoadTimeout(3,TimeUnit.MILLISECONDS);
对此:
driver.manage().timeouts().pageLoadTimeout(3,TimeUnit.SECONDS);
我认为你的超时是因为你在页面加载时有超过3毫秒的超时。这可能完全太短了。 3秒似乎更合理。