I am using this code with ChromeDriver and Chrome browser:
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(20));
Thread.sleep(20000);
driver.quit();
Then webpage keeps loading more than 20 seconds and closing with java.util.concurrent.TimeoutException
But its not working.
You can try this:
import org.openqa.selenium.TimeoutException;
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(20));
try {
driver.get("https://www.amazon.com");
} catch (TimeoutException e) {
// e.printStackTrace();
System.out.println("Quitting...");
driver.quit();
}