6

A page I am testing has a button that takes you to a different page on the same site. After clicking on that button, I want to wait for that page to load before continuing. Normally, I would just wait for some element on that page to load, but since I recently updated nightwatch/selenium, that waitForElementPresent() test has stopped working. In the process of debugging the problem, I thought it made sense to wait for the new URL to load, but I don't see a nightwatch way to do that. I can hard code a wait with a pause() followed by an assert.urlContains(), but there's got to be a better way. Any suggestions?

What used to work:

this.waitForElementVisible(runCSS,3000)
    .click(runCSS)
    .waitForElementPresent(newPageElementCSS,5000)

but now it times out on the second wait, even though I can clearly see the new page on the browser display (Firefox 45.0.1 on Windows 8.1).

Bryn Wolfe
  • 183
  • 1
  • 1
  • 14
  • if the tests don't work as they used to after the update, maybe try to update the selenium-server-standalone to the latest too? there were some compatibility issues with older versions and latest mozilla. – anasarbescu Apr 10 '16 at 00:28

2 Answers2

1

Wait for something (a selector) that is unique to the page that will be loaded after the click. It can be anything as long as it doesn't exist on the current page.

For example,

This would wait for <div name="Thingy"> anywhere on the page:

client.waitForElementVisible('div[name="Thingy"]',3000)
eyn
  • 778
  • 2
  • 10
  • 21
  • Is there a way to set up a "suite-wide" default timeout much like rspec+capybara 's global timeout? so that we won't have to .waitForElementVisible after every other assertion – Nick M Feb 18 '19 at 07:43
-1

I guess, in Nightwatch.js, wait for the page to load can be achieved using 'body' element of the DOM. Suppose, if we want to wait the page for 1 second. we will achieve it using the command .waitForElementVisible('body', 1000). The second parameter is measured in ms.

Community
  • 1
  • 1
Janardhan Reddy
  • 156
  • 1
  • 8
  • 5
    This won't necessarily work if there is a body element on the old page too. If the new page has not yet loaded and old page is still visible (i.e. immediately after clicking a link), I assume the old page will have a `body` and this condition will be met before the new page has loaded. Better to wait for an element that you know exists on the new page, and does not exist on the first (if this is possible) – GrayedFox Jan 11 '17 at 17:04
  • 3
    To add on to GrayedFox's comment, this also would not work if you're doing any sort of single page app with HTML5 navigation - the page will not load but content of the page instead gets replaced and URL changes through use of `history.pushState()` – thom_nic Mar 06 '17 at 16:31