Need details about Page load strategy for Chromedriver

0 votes
I'm using Chrome for testing a page. At times, the pages load after a long time. I need to find a way to stop downloading or atleast limit their download time.

I know that in FireFox, I can use PAGE_LOAD_STRATEGY = "eager". Is there anything similar for Chrome?

Even though driver.manage().timeouts().pageLoadTimeout() works, after that, any treatment to Webdriver throws TimeOutException. I want the current url of the page after stopping its boot.
May 30, 2018 in Selenium by eLiJha
• 720 points
2,436 views

1 answer to this question.

0 votes

According to WebDriver docs, when Page Loading takes lot of time, then you need to stop downloading additional subresources like (images, css, js etc) and you can modify the pageLoadStrategy through WebDriver.

As of now, pageLoadStrategy supports the following values:

normal:-
This will make Selenium wait till the entire page is loaded. (html content and subresources downloaded and parsed).

eager:-
This will make Selenium wait for DOMContentLoaded event (html content downloaded and parsed only).

none:-
This will make Selenium to return immediately after the initial page content is completely received (html content downloaded).

By default, when Selenium loads a page, it follows the normal pageLoadStrategy. You can implement it using DesiredCapabilities() with firefox or ChromeOptions() for chrome. Usage is below.

DesiredCapabilities-

System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");

        DesiredCapabilities dcap = new DesiredCapabilities();

        dcap.setCapability("pageLoadStrategy", "normal");

        FirefoxOptions opt = new FirefoxOptions();

        opt.merge(dcap);

        WebDriver driver = new FirefoxDriver(opt);

        driver.get("https://www.google.com/");

        System.out.println(driver.getTitle());

        driver.quit();

ChromeOptions-

        System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");

        FirefoxOptions opt = new FirefoxOptions();

        opt.setPageLoadStrategy(PageLoadStrategy.NORMAL);

        WebDriver driver = new FirefoxDriver(opt);

        driver.get("https://www.google.com/");

        System.out.println(driver.getTitle());

        driver.quit();
answered May 30, 2018 by king_kenny
• 3,650 points

Related Questions In Selenium

0 votes
1 answer

Wait for page to load using HtmlUnitDriver

You can create a custom ExpectedCondition public static ...READ MORE

answered May 7, 2018 in Selenium by anonymous
496 views
0 votes
1 answer

I need to release the memeory allocated to Selenium chromedriver.exe while for tests

The usage of the commands is incorrect. driver.close() ...READ MORE

answered May 21, 2018 in Selenium by sniffy_god
• 780 points
695 views
0 votes
2 answers
0 votes
1 answer

Is it possible for a website to detect that we are using Selenium with ChromeDriver

Selenium tests for pre-defined javascript variables which ...READ MORE

answered Apr 27, 2018 in Selenium by Meci Matt
• 9,420 points
2,183 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
577 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
898 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
567 views
0 votes
1 answer

Need to scroll down for locating an Element with Selenium

There are a couple of options for ...READ MORE

answered Apr 20, 2018 in Selenium by king_kenny
• 3,650 points
420 views
0 votes
1 answer

Selenium Alternatives: Is there a tool like Selenium for testing web pages but which does not involve coding.

I'm guessing you've tried Selenium IDE already. ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,650 points
68 views