Sometimes, when I want to load a page, something happen with scripts and block the browser.
With this html I can simulate the exact problem:
<html>
<head>
<script>
while(true){}
</script>
</head>
<body>
<div id='stuck'>
I'm stuck.
</div>
</body>
</html>
I try to run my code on the above page:
ChromeOptions coptions = new ChromeOptions();
coptions.setCapability("pageLoadStrategy", "none");
//rootOfProject/data/chromedriver.exe
System.setProperty("webdriver.chrome.driver", "data/chromedriver.exe");
WebDriver driver = new ChromeDriver(coptions);
driver.manage().window().maximize();
driver.get("file:///.../stuckbrowser.html");
WebDriverWait wdw = new WebDriverWait(driver, 10);
//using debugger it stuck here
//more than 10 seconds(infintely) - because browser is frozen from script in <head>
String text = wdw.until(ExpectedConditions.visibilityOfElementLocated(By.id("stuck"))).getText();
System.out.println(text);
driver.quit();
System.out.println("Done");
My code get stuck when I try to getText()
of element with id = stuck
.
It stays there more than 10 seconds(how much? I don't know. I think it's infinitely).
There can be a way to stop scripts(from webpage) which run more than x seconds?