Selenium chromeDriver open extremely slower than open a website in chrome browser directly

Rogers Shu picture Rogers Shu · May 23, 2017 · Viewed 9.2k times · Source

I met a disgusting issue regarding the speed of Selenium Webdriver when opening a website.

The website which I am testing is a internal website, so it is not accessible for you. In order to describe my issue in detail, I will refer to the website as ABC.

When I type ABC's URL in Chrome browser, it only takes 1 seconds to open this website.

In TestNG my Selenium client looks like this:

String ABC = "ABC'S URL";
String chromeDriverPath = "C:\\selenium\\chromedriver.exe" ;
System.out.println("start selenium");
File file = new File(chromeDriverPath);
System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
webDriver driver = new ChromeDriver(options);
driver.get(ABC);

Then, Chrome will be controlled by automated testing software. On the footprint, there will be a note that says waiting for staticxx.fackbook.com, or waiting for www.facebook.com.

After 1 minute , ABC website has been successfully loaded. I check F12 tool and in console it says staticxx.facebook.com/connect/xd_arbiter/r/0F7S7QWJ0Ac.js?version=42#channel=f38f3479a8af658&origin=http% Failed to load resource: the server responded with a status of 503 (Service Unavailable).

Is there any Selenium API which could avoid loading certain web resources? Or, could I do some configuration on browser to stop loading certain web resources?

Thank you all in advance!

Answer

DebanjanB picture DebanjanB · May 23, 2017

Here is the Answer for your Question:

To avoid loading certain website, you can utilize a feature of Chrome Browser by tweaking the pageLoadStrategy through DesiredCapabilities Class and set it to none as follows:

String ABC = "ABC'S URL";
String chromeDriverPath = "C:\\selenium\\chromedriver.exe" ;
System.out.println("start selenium");
File file = new File(chromeDriverPath);
System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability("pageLoadStrategy", "none");
webDriver driver = new ChromeDriver(capabilities);
driver.get(ABC);

Let me know if this Answers your Question.