mercredi 18 juillet 2018

Java selenium - how to properly refresh a webpage after TimeoutException?

     ChromeOptions options = new ChromeOptions();
       options.addExtensions(new File("extension_6_2_5_0.crx")); //ZenMate
       options.addExtensions(new File("extension_2_9_2_0.crx")); //AdGuard
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        driver = new ChromeDriver(options);
          driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); //Timeout after 10 seconds

This is how I set my Chrome Driver

   try {
        driver.navigate().to("http://dic.naver.com/");
    }catch (TimeoutException e){
        System.out.println("Time out Exception");
        driver.navigate().refresh();
    }

This is my code.

I run it, then it catches TimeoutException as it is supposed to, but then the browser stops taking any get() or navigate().to() or refresh commands.

Starting ChromeDriver 2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9) on port 6823
Only local connections are allowed.
Jul 18, 2018 8:47:45 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[1531936076.034][SEVERE]: Timed out receiving message from renderer: 4.660
[1531936076.633][SEVERE]: Timed out receiving message from renderer: -0.606
Time out Exception
[1531936090.525][SEVERE]: Timed out receiving message from renderer: 10.000
[1531936090.563][SEVERE]: Timed out receiving message from renderer: -0.057
Exception in thread "main" org.openqa.selenium.TimeoutException: timeout
  (Session info: chrome=67.0.3396.99)
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.17134 x86_64) .remote.RemoteWebDriver$RemoteNavigation.refresh(RemoteWebDriver.java:856)
    at Markov.Bots.Bot_Kancolle.stay(Bot_Kancolle.java:43)
    at Markov.Scroller.main(Scroller.java:71)

Instead it throws another TimeoutException when it executes driver.navigate().refresh(); at line 43

The browser simply stops at TimeoutException, does not refresh, does not connect to new URL when I execute another driver.get()

How do I properly catch TimeoutException and reuse this browser for next URL connection???




Aucun commentaire:

Enregistrer un commentaire