1011011
1011011

Reputation: 61

Java selenium how to reload a webpage after TimeOutException?

driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); //Timeout after 10 seconds

I am using ChromeDriver. This is the code I used to set timeout.

try {
    System.out.println("Selenium connected to " + haruhi.link);
    driver.navigate().to(haruhi.link);  //URL to connect
} catch (UnhandledAlertException e) {
    driver.switchTo().alert().accept();
} catch (TimeoutException e) {
    System.out.println("Timeout, Skip this page");
   skip = true;
} catch (NoSuchWindowException e) {
    skip = true;
}
 if (!skip) {
...
}

This is the code that connects to URL.

This code is inside a for loop that iterates the list of String of URLs. Once "skip" is set true, it does nothing about that webpage and connects to next URL on the next iteration in loop.

What I want to do is when a webpage is hanging (stuck in an infinite load), I want to catch TimeoutException, skip that webpage and connect to next URL in the loop.

enter image description here

But once TimeoutException is caught, the code connects to the next URL, but the Chrome does not receive that command. It prints out

"Selenium connected to http://gall.dcinside.com/board/comment_view/?id=comic_new1&no=5518557&page=1"

But chrome URL still displays

"http://gall.dcinside.com/board/comment_view/?id=comic_new1&no=5518554&page=1"

meaning that driver.get(); did not work.

How do I properly use TimeoutException?

Upvotes: 1

Views: 730

Answers (1)

Murthi
Murthi

Reputation: 5347

try with the following code,

driver.navigate().refresh();

Upvotes: 1

Related Questions