1

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?

KunLun
  • 3,109
  • 3
  • 18
  • 65
  • Can you post the code that initializes your web driver? You might want to read [Selenium determine browser is frozen](https://stackoverflow.com/q/14528001/3092298). The question is about Selenium and Python, but the answer in Java might be similar. – Greg Burghardt Feb 24 '20 at 16:48
  • @GregBurghardt I updated my question with info of how I start driver. – KunLun Feb 24 '20 at 16:58

0 Answers0