Stop the loading time in a mobile web page with appium

We have an automated test in Java, but the page I’m testing takes too much loading . Sometimes it can take at least 60 seconds. we need to detect this time and stop the page loading (The page only loads unnecessary things after 30 seconds) and continue with the process (Selenium wait until the page is completely load to continue with ne next step).

we tried to use a Thread, but it didn’t work, and we don’t understand why

driver.manage().timeouts().pageLoadTimeout(60000, TimeUnit.MILLISECONDS);
Thread jsInjector = new Thread(){
        @Override
        public void run() {
            super.run();
            try {
                Thread.sleep(30000);
                JavascriptExecutor jsi = (JavascriptExecutor) dr;
                jsi.executeScript("window.stop()");
                System.out.println("#### Stop loading page #####");
            } catch (InterruptedException e) {

            }
        }
    };
jsInjector.start();
driver.get(url);
sleepProcess(randTime());
jsInjector.interrupt();

if you insist that Selenium waits page to load this = driver.get(url) will NOT end until page loaded.

1 Like