0
votes

Is there any function available in Watir Webdriver to wait for a new window tab to load?

What happens right now is the tests are not waiting for the tab to load and my scripts are failing because of that.

I know that i can wait for some elements available in the web page. But i dont want to do that for each web page. If there is no method available, i would like to write a new method for the same as a library in my framework.

I am new to watir webdriver and ruby programming. So please help me to write a library function in case not available...

1
Is the problem (1) that Watir is looking for the tab before it is opened or (2) that Watir is looking for an element that is asynchronously loaded before it is created?Justin Ko
@JustinKo What i am observing is : Tests are not waiting for page to load. Yes, watir is looking for an element even before the page load. Because of that tests were failing due to object not found or not visible or something like that. If i add some implicit wait there, it works fine. So definitely there is some issue.Sukuva

1 Answers

1
votes

I may be misunderstanding, but your question seems to say two different things. On the one hand, you say that Watir doesn't wait for the page to load. But then you say you know that Watir can wait but you don't want to do that on every page.

In my experience, and again I may be misunderstanding, if Watir is going too fast and your page isn't loading, you have no choice but to have Watir wait on any page where this is a problem. What else did you have in mind?

If your page loads within 30 seconds you can use .wait_until_present or .when_present. (i.e., Watir will move on as soon as the element is available and will time out after half a minute).

For example, if your loaded page has the text "Hello" in a div, you can make Watir wait for up to 30 seconds for that text to appear by

browser.div(:text, 'Hello').wait_until_present

and then let your test pick up where it left off.

Or, if there is (as an example) a button with id "buttonId" that you want to click when the page loads, you can make Watir wait for up to 30 seconds until the button is loaded and clickable:

browser.button(:id, 'buttonId').when_present.click

I almost always use .wait_until_present or .when_present. for each new page load. Under normal circumstances 30 seconds is long enough for the page to be ready for Watir, and these two methods work very well.

See also http://watirwebdriver.com/waiting/