6

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!

iamdanchiv
  • 4,052
  • 4
  • 37
  • 42
Rogers Shu
  • 93
  • 1
  • 1
  • 5
  • 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`? Thanks – undetected Selenium May 23 '17 at 07:37
  • 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. – Rogers Shu May 23 '17 at 08:27
  • 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. – Rogers Shu May 23 '17 at 08:41
  • Checkout my Answer. Thanks – undetected Selenium May 23 '17 at 08:42

1 Answers1

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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • still need to wait ABC website full completion. so sad. – Rogers Shu May 23 '17 at 09:26
  • 1
    i found https://stackoverflow.com/questions/43734797/page-load-strategy-for-chrome-driver why this works for him....not me ... thank you all the same – Rogers Shu May 23 '17 at 09:49
  • @RogersShu I can help you with some other strategy but in that case you have to share the actual URL & your work. Thanks – undetected Selenium May 23 '17 at 10:27
  • 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. – Rogers Shu May 24 '17 at 06:40
  • I accepted your answer that your resolution could resolve this kind of issue. I hope it could help others in this scenario – Rogers Shu May 24 '17 at 06:44
  • @RogersShu Great thinking. Thanks – undetected Selenium May 24 '17 at 06:52