0

I am writing Test Cases using Selenium web Driver. I need to setup implicit wait for Chrome driver. I don't need explicit-it is too long! Is there any way to force Google Chrome driver throw a TimeOutException or (refresh page would also work) after 5 seconds of its attempt to upload a page.

I tried: driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

It does not work. Here is the brief source code:

.......
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
.......
.......
element.click();
.......

Now I need the driver to throw a TimeOutException if the page does not load within 5 seconds.

hexacyanide
  • 88,222
  • 31
  • 159
  • 162

2 Answers2

0

There is another kind of wait: pageLoadTimeout. Here is how you use it:

driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);

See "Interface WebDriver.Timeouts" for more information.

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
Buddha
  • 4,339
  • 2
  • 27
  • 51
  • I tried this either: driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS); It does not work with Chrome. It throws Unsupported Operation exception. Firefox seems to allow for this command, however, it appears that it gets suppressed if there is at least one explicit wait anywhere present. :( –  Feb 12 '13 at 20:26
  • @Petrov , Looks like there is an open issue for Chrome on this exact item. Hopefully this gets fixed quickly... http://code.google.com/p/chromedriver/issues/detail?id=9 – Buddha Feb 20 '13 at 18:29
0

There is an easier way of doing it... You do not have to over complicate your code with WebDriverTimeouts etc...You can simply install Chrome Auto Refresh Plus on your browser and choose it to auto refresh say after 5 seconds. For every loop or whatever you have, the browser is going to provide you with 5 seconds to complete it, otherwise it is going to refresh the page, as you want it. Just install Auto Refresh: https://chrome.google.com/webstore/detail/auto-refresh-plus/oilipfekkmncanaajkapbpancpelijih?hl=en

PC: implicit waits are not doing well with Chrome: http://www.google.com/url?sa=t&rct=j&q=implicit+waits+issue+Chrome&source=web&cd=1&cad=rja&ved=0CC8QFjAA&url=http%3A%2F%2Fcode.google.com%2Fp%2Fchromedriver%2Fissues%2Fdetail%3Fid%3D24&ei=vz5HUY6mIYS_rQH3zYFI&usg=AFQjCNFar_7Cz3E5nJiYiGRg_ftXCLVuaQ&sig2=Jl7N0OH0usXBTXEjOvzBUw&bvm=bv.43828540,d.aWM

CHEBURASHKA
  • 1,623
  • 11
  • 53
  • 85
  • @Petrov - If this works best for you that is well and good. However I don't see the relation between the questions and answer, unless I'm missing some information. If it is auto refresh mechanism in browser you wanted, yes, Kyle's anwer would work, however, you may have to find similar add-ons for other browser in case if you want to test them on other browsers, but question seemed like you wanted to throw an exception incase if the page is not loaded in 5 sec, as if it is a performance test. Anyways, have a great time automating. – Buddha Mar 24 '13 at 18:49
  • @Buddha, I must correct you. Actually once a WebDriver is launched, it has no add-ons, so one would need to install them while the program is running. Given this, Firefox, for example, needs to be restarted, which would throw an error... Auto refresh is not the best way, but it is the easiest, and can be implemented only with Chrome. – CHEBURASHKA Mar 25 '13 at 03:40
  • @Kyle nope.. it is possible to install the required addon in a specific profile in firefox and open that profile instead of default temporary profile. So, it is possible even in firefox. Check these.. http://stackoverflow.com/questions/6787095/how-to-stop-selenium-from-creating-temporary-firefox-profiles-using-web-driver http://stackoverflow.com/questions/7615193/using-a-specific-firefox-profile-in-selenium-2-webdriver-in-c-sharp – Buddha Mar 26 '13 at 16:23
  • My apologies to @Buddha. It is possible to open an existing profile with all the adds installed. – CHEBURASHKA Mar 27 '13 at 02:13