user3078768
user3078768

Reputation: 1

Webdriver blocks due to timeout

MacOS + Java + Eclipse + Firefox + Webdriver. Lastest version

 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();
    }
}

simplest code. always blocked in line driver.get("http://www.google.com");.an internal exception is thrown and catch doesn't work here. Timeout is inevitable in my program. How can I cancel the block totally? Google result suggests a new thread, which may not be reliable.

 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)

Upvotes: 0

Views: 7663

Answers (1)

Richard
Richard

Reputation: 9019

Change this line:

driver.manage().timeouts().pageLoadTimeout(3,TimeUnit.MILLISECONDS);

To this:

driver.manage().timeouts().pageLoadTimeout(3,TimeUnit.SECONDS);

I think you're timing out because you have a 3 millisecond timeout on page load. That's probably entirely too short. 3 seconds seems a lot more reasonable.

Upvotes: 1

Related Questions