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

1

7

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!

Photic answered 23/5, 2017 at 7:28 Comment(4)
I think I have a solution for you but I need to understand your exact requirement first. What do you exactly mean by avoid loading certain web? ThanksOperator
for example. I visit ABC website ,in ABC website ,there is a link refers to facebook.com. In my testing , i don't need test facebook.com. But i have to wait for all request on ABC then ABC website renders. It costs me too much time.Photic
Actually, when i call driver.get("ABC website"); it only takes several seconds to get the elements rendered . That's enough. I don't want to wait too long for that useless staticxx.facebook.com response.Photic
Checkout my Answer. ThanksOperator
O
1

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.

Operator answered 23/5, 2017 at 8:40 Comment(6)
still need to wait ABC website full completion. so sad.Photic
i found #43735297 why this works for him....not me ... thank you all the samePhotic
@RogersShu I can help you with some other strategy but in that case you have to share the actual URL & your work. ThanksOperator
Hi Dev URL is in DMZ. Finally i got this issue resolved. I used proxy integrated in selenium and block url like facebook. It works. Also thanks to your advice. I think your resolution won't work for me because element invoke url like facebook is in a web front structure and pageLoadStrategy cannot ignore.Photic
I accepted your answer that your resolution could resolve this kind of issue. I hope it could help others in this scenarioPhotic
@RogersShu Great thinking. ThanksOperator

© 2022 - 2024 — McMap. All rights reserved.