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?