0

I am trying to access a website using Selenium WebDriver, but the website will keep loading although I can still interact with it. (The website is nitrotype.com if you are wondering.) I think it is because driver.get() waits until the page is fully loaded. Can I bypass this until just a certain element loads ?

TL;DR How do I bypass the driver.get() waiting until a site is completely loaded before proceeding?

2
  • what do you mean by website will keep loading ? I tried and can interact with it right away. Commented May 5, 2021 at 14:45
  • The website will keep loading, but you can interact with it before it finishes loading. Commented May 6, 2021 at 12:27

1 Answer 1

0

Look into page load strategy: https://www.selenium.dev/documentation/en/webdriver/page_loading_strategy/ Normal, Eager & None are your options. I suggest you combine your strategy with the proper explicit wait.

NORMAL

normal This will make Selenium WebDriver to wait for the entire page is loaded. When set to normal, Selenium WebDriver waits until the load event fire is returned.

By default normal is set to browser if none is provided.

EAGER

eager This will make Selenium WebDriver to wait until the initial HTML document has been completely loaded and parsed, and discards loading of stylesheets, images and subframes.

When set to eager, Selenium WebDriver waits until DOMContentLoaded event fire is returned.

NONE

none When set to none Selenium WebDriver only waits until the initial page is downloaded.

To implement:

public class pageLoadStrategy {
    public static void main(String[] args) {
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
        WebDriver driver = new ChromeDriver(chromeOptions);
        try {
            // Navigate to Url
            driver.get("https://google.com");
        } finally {
            driver.quit();
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.