google chrome - Selenium ChromeDriver C# how to navigate page before it loads? -


i testing data flow client's website. has advertisements take substantially longer load data elements of each page test selenium commands.

i don't have control on ads , can't silence them.

i navigate each page clicks prior complete page loading. know possible because can manually using mouse. however, despite attempts stubborn chromedriver not begin automation until entire page loaded.

i using c# .net 4.6.1, chrome32_55.0.2883.75, , selenium version 3.0.1.0.

further, using recommended selenium page object model. implemented waitforload() this:

    public override void waitforload()     {         _isloaded = wait.until(d =>         {             lock (d)             {                 switchtoself();                  return pageregex.ismatch(session.driver.pagesource);                                 }         });     }  

the pageregex above work after full page loaded. frustrating because can visually see text string pageregex designed parse on screen. leads me believe there setting elsewhere, perhaps while configuring chromedriver, enable me parse session.driver.pagesource prior being loaded.

this how instancing chromedriver:

            var options = new chromeoptions();              options.addarguments("test-type");               options.addargument("incognito"); // works             options.addargument("--disable-bundled-ppapi-flash"); // works! turns off shockwave             options.addargument("--disable-extensions"); // works             options.addarguments("--start-fullscreen");              string workfolder = environment.getfolderpath(environment.specialfolder.desktop) +                                                  "\\shared";              options.binarylocation = workfolder + @"\chrome32\chrome32_55.0.2883.75\chrome.exe";             var driver = new chromedriver(options);             driver.manage().cookies.deleteallcookies();             return driver; 

to interact page before has finished loading, can either lower timeout , catch exception:

iwebdriver driver = new chromedriver(); webdriverwait wait = new webdriverwait(driver, timespan.fromseconds(5));  driver.manage().timeouts().setpageloadtimeout(timespan.frommilliseconds(500));  try {     driver.navigate().gotourl("http://www.deelay.me/5000/http://www.deelay.me/"); } catch (openqa.selenium.webdrivertimeoutexception) { }  // waits element  var body = wait.until(expectedconditions.elementexists(by.cssselector("body"))); 

or can disable waiting setting page load stategy none :

var options = new chromeoptions(); options.addadditionalcapability("pageloadstrategy", "none", true);  iwebdriver driver = new chromedriver(options); webdriverwait wait = new webdriverwait(driver, timespan.fromseconds(5));  driver.navigate().gotourl("http://www.deelay.me/5000/http://www.deelay.me/");  // waits element  var body = wait.until(expectedconditions.elementexists(by.cssselector("body"))); 

Comments