user1572637
user1572637

Reputation: 41

How to make Selenium WebDriver not to wait for complete load of the page

Some of our pages have 3rd party analytics running on the back end. It seems to me that selenium is waiting for those process to finish before going to the next step. The problem is that it takes around 5-6 minutes. Is there any way to aboard this wait and to move on to the next step?

I tried clicking on the button (which takes user to the page that has some backend processes) with JavaScript click, that worked, but then it gets stuck on the next step.

Thanks.

Upvotes: 4

Views: 3752

Answers (2)

Erki M.
Erki M.

Reputation: 5072

I would suggest that you could make use of a proxy. Browsermob integrates well with selenium, very easy to use it:

// start the proxy
ProxyServer server = new ProxyServer(4444);
server.start();

// get the Selenium proxy object
Proxy proxy = server.seleniumProxy();

// This line will automatically return http.200 for any request going to google analytics
server.blacklistRequests("https?://.*\\.google-analytics\\.com/.*", 200);

// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);

// start the browser up
WebDriver driver = new FirefoxDriver(capabilities);

EDIT: I just discovered, that in selenium 2.40, the pageLoading strategy is implemented.

  • Implemented pageLoadingStrategy capability in Firefox.
partial interface WebDriver {
    const DOMString CONSERVATIVE = 'conservative';
    const DOMString NORMAL = 'normal';
    const DOMString EAGER = 'eager';
    const DOMString NONE = 'none';
};

reference

Upvotes: 0

Prashanth Sams
Prashanth Sams

Reputation: 21129

Clicking an Element on page load is even possible on webdriver; By default, webdriver wait for the entire page to load and then picks the element. The links and texts are visible but they are not clickable; However, it works well on Selenium IDE picking elements on page load.

Webdriver make use of the FirefoxProfile to avoid such risks; It's applicable only for Firefox browser.

FirefoxProfile fp = new FirefoxProfile();
fp.setPreference("webdriver.load.strategy", "unstable");
driver = new FirefoxDriver(fp);

Upvotes: 3

Related Questions