rubywatirwatir-webdriverwebautomation

Watir-webdriver: how to force the click method to wait for the page to load completely


I recently started using Watir-Webdriver after previously using Watir since I needed some functionality which was present in webdriver but not in Watir. I am facing a problem in watir-webdriver which I never faced in Watir.

Whenever one used the click method on a button in Watir, it used to implicitly wait till the new page is loaded completely. I read on the Watir-webdriver docs that the waiting and in this question that the waiting in watir-webdriver has been changed so as to accommodate the dynamic changes made to a webpage made by AJAX. Now, the page which I am automating does not have any AJAX elements, it only contains static elements.

But when I used the click method in watir-webdriver, it does not wait for the next page to load implicitly and executes the next line in the call immediately. I could use is wait_until_present but to do it for lots of pages seems like an overkill to me when waiting for a page to load on a click seems to be the standard behavior.

Am i missing some options which I need to toggle so that the click method of Watir is emulated in watir-webdriver?


Solution

  • If you are having problems where the browser is indicating the page is loaded, but stuff is still happening client side (might be javascript code executing, or css logic etc) then I'd suggest using the 'when_present' decorator in front of your action.

    That's a little cleaner than having to put in a separate wait step, and is a lot better than fixed sleep periods etc.

    browser.button(:how => 'what').when_present.click