waitWhileVisible()

waitWhileVisible(selectors [, timeout, condition, callback])

Waits for a list of selectors CSS selectors to become non-visible.
Aborts with an error if the elements are still visible after timeout milliseconds.

const selectors = "#header > h1.big-title"
const pageTimeout = 5000

try {
  await tab.waitWhileVisible(selectors, pageTimeout)
  // The selector has succesfully become non-visible
} catch(err) {
  console.log("Oh no! Even after 5s, the element was still visible:", err)
}
const selectors = "#header > h1.big-title"
const pageTimeout = 5000

tab.waitUntilVisible(selectors, pageTimeout)
.then(() => {
  // The selector has succesfully become non-visible
})
.catch((err, selector) => {
  console.log("Oh no! Even after 5s, the element was still visible:", err)
  console.log("This element is visible: ", selector)
})
var selectors = "#header > h1.big-title"
var pageTimeout = 5000

tab.waitUntilVisible(selectors, pageTimeout, function(err, selector) {
  if (err) {
    console.log("Oh no! Even after 5s, the element was still visible. ", err)
    console.log("This element is visible: ", selector)
  } else {
    // The selector has succesfully become non-visible
  }
})

selectors can be an array of CSS selectors (array of strings) or a single CSS selector (string).

By default, condition is "and" (wait for all CSS selectors) but it can be changed to "or" (wait for any CSS selector).

— selectors (Array or String)

What to wait for. Can be an array of CSS selectors (array of strings) or a single CSS selector (string).

— timeout (Number)

The maximum number of milliseconds to wait for, by default it is set to 5000 (optional).
callback will be called with an error if the elements are still visible after timeout milliseconds.

— [condition] (String)

When selectors is an array, this optional argument lets you choose how to wait for the CSS selectors(optional).
If condition is "and" (the default), the method will wait for all CSS selectors.
On the other hand, if condition is "or", the method will wait for any CSS selector.

— callback (Function(err, selector))

Function called when finished(optional).

  • err (String): null or a description of what went wrong if the CSS selectors were still visible after timeout milliseconds
  • selector (String):
    • In case of success (err is null):
      • If condition was "and" then selector is null because none of the CSS selectors are visible
      • If condition was "or" then selector is one of the non-visible CSS selectors of the given array
    • In case of failure (err is not null):
      • If condition was "and" then selector is one of the still visible CSS selectors of the given array
      • If condition was "or" then selector is null because all of the CSS selectors are still visible