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

10,401

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.

Share:
10,401
Rogers Shu
Author by

Rogers Shu

Updated on June 27, 2022

Comments

  • Rogers Shu
    Rogers Shu almost 2 years

    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!

    • undetected Selenium
      undetected Selenium almost 7 years
      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
    • Rogers Shu
      Rogers Shu almost 7 years
      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
      Rogers Shu almost 7 years
      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.
    • undetected Selenium
      undetected Selenium almost 7 years
      Checkout my Answer. Thanks
  • Rogers Shu
    Rogers Shu almost 7 years
    still need to wait ABC website full completion. so sad.
  • Rogers Shu
    Rogers Shu almost 7 years
    i found stackoverflow.com/questions/43734797/… why this works for him....not me ... thank you all the same
  • undetected Selenium
    undetected Selenium almost 7 years
    @RogersShu I can help you with some other strategy but in that case you have to share the actual URL & your work. Thanks
  • Rogers Shu
    Rogers Shu almost 7 years
    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
    Rogers Shu almost 7 years
    I accepted your answer that your resolution could resolve this kind of issue. I hope it could help others in this scenario
  • undetected Selenium
    undetected Selenium almost 7 years
    @RogersShu Great thinking. Thanks