0

I have a selenium app which execute non-stop.

I have this peace of code:

driver.get(url);
waitLoadComplet(driver, 60);

//////////////////////////////////////////////////

public void waitLoadComplet(WebDriver driver, int secs){

    int seconds = 0;
    while(seconds < secs){

        if(getState(driver).equals("complete")){ 
             return; 
        }

        try{ Thread.sleep(1000); }catch(Exception ignored){}
        seconds++;

    }

}

//////////////////////////////////////////////////

// return -> uninitialized / loading / loaded / interactive / complete
public String getState(WebDriver driver){

    return (String) ((JavascriptExecutor)driver).executeScript("return document.readyState");

}

driver is started with chromeOptions.setCapability("pageLoadStrategy", "none") to not get stuck at driver.get(url).

Because of the internet connection, sometimes page load hard, so I want to go ahead after 60 seconds, even if page is still loading.

So I have this method waitLoadComplet which checks once per second the state of browser and if state is complete go ahead.

But, sometime my app get error in method getState:

ScriptTimeoutException: script timeout

    - (Session info: chrome=80.0.3987.116) 
    - Build info: version: 'unknown', revision: 'unknown', time: 'unknown' 
    - System info: host: 'DESKTOP-14FK2D6', ip: '192.168.0.248', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '10.0.1' 
    - Driver info: org.openqa.selenium.chrome.ChromeDriver 
    - Capabilities {
        acceptInsecureCerts: false, 
        browserName: chrome, 
        browserVersion: 80.0.3987.116, 
        chrome: {chromedriverVersion: 80.0.3987.106 (3582db32b3389..., userDataDir: C:\Users\AAA\AppData\Local\...}, 
        goog:chromeOptions: {debuggerAddress: localhost:49274}, 
        javascriptEnabled: true, 
        networkConnectionEnabled: false, 
        pageLoadStrategy: none, 
        platform: WINDOWS, 
        platformName: WINDOWS, 
        proxy: Proxy(), 
        setWindowRect: true, 
        strictFileInteractability: false, 
        timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, 
        unhandledPromptBehavior: dismiss and notify} 
    - Session ID: 308f4bd58af8d50cd9078f14336763fa

Selenium version is 3.141.59.

Because the code execute non-stop, I can't monitor it all the time and this error always happen when I'm not looking.

The main problem is after I get ScriptTimeoutException. The program stuck there for a while(after error). Sometimes 2 hours, sometime 20 mins, random time. In this time nothing happen(nothing in log).

What can occur this ScriptTimeoutException and why it stucks there for a while?

KunLun
  • 3,109
  • 3
  • 18
  • 65
  • Did you try to use `driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS)` and try/catch for `driver.get()`? – Sers Feb 21 '20 at 12:52
  • @Sers I didn't tried that, because the waiting time it's not a fix value. There are cases when is more than 60. – KunLun Feb 21 '20 at 12:57
  • Try it on one problem url, without your `waitLoadComplet`and `chromeOptions.setCapability("pageLoadStrategy", "none")`. The problem happen only when browser is on the background? Do you run in headless mode – Sers Feb 21 '20 at 13:01
  • @Sers I will. But there is not a specific bad URL. I will come back after I have a conclusion. – KunLun Feb 21 '20 at 13:03
  • My question is not duplicate...You read my question @DebanjanB? I know how to check if page is loaded. My question is why sometimes(random page) I get `ScriptTimeoutException` when I try to get `document.readyState`. – KunLun Feb 22 '20 at 09:28

0 Answers0