Selenium chromeDriver open extremely slower than open a website in chrome browser directly
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.
Rogers Shu
Updated on June 27, 2022Comments
-
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
, orwaiting for www.facebook.com
.After 1 minute ,
ABC
website has been successfully loaded. I checkF12
tool and in console it saysstaticxx.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 almost 7 yearsI 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 almost 7 yearsfor 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 almost 7 yearsActually, 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 almost 7 yearsCheckout my Answer. Thanks
-
-
Rogers Shu almost 7 yearsstill need to wait ABC website full completion. so sad.
-
Rogers Shu almost 7 yearsi found stackoverflow.com/questions/43734797/… why this works for him....not me ... thank you all the same
-
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 almost 7 yearsHi 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 almost 7 yearsI accepted your answer that your resolution could resolve this kind of issue. I hope it could help others in this scenario
-
undetected Selenium almost 7 years@RogersShu Great thinking. Thanks