Skip to content Skip to sidebar Skip to footer

Proper Way To Limit Wait Time On Selenium Element Search

My nightwatch/selenium test code looks for elements in the page that may not exist using code such as browser.elementIdElement(ELEMENT,'class name', 'myclass', function(r) { if

Solution 1:

Perhaps I am misunderstanding your problem; both of these patterns works well for me:

client
.useXpath().waitForElementPresent(selector, this.timeout)
.useCss().waitForElementPresent(selector, this.timeout)

this.timeout is set in the prototype of the base test case.

util.inherits(MyExampleBaseClass, Base);

MyExampleBaseClass.prototype = {
  before: function (client) {
    // call super-beforeBase.prototype.before.call(this, client);
    this.timeout = 250;
  },

  after: function (client, callback) {
    // call super-afterBase.prototype.after.call(this, client, callback);
  },

  // Note: This method will not be mistaken by nightwatch for a step because// it is not enumerable (since it's on the prototype)getSiteURL: function () {
    return"http://www.urlundertest.com/";
  }
};

Solution 2:

The following code for checking the visibility and continue even if there is no match

browser.waitForElementVisible('selector',timeout,false);

or this for the existence :

browser.waitForElementPresent('selector',timeout,false);

According to nightwatch api,

By the default if the element is not found the test will fail. Set this to false if you wish for the test to continue even if the assertion fails.To set this globally you can define a property abortOnAssertionFailure in your globals.

For more detailed explanation, check here: http://nightwatchjs.org/api/#waitForElementVisible

Post a Comment for "Proper Way To Limit Wait Time On Selenium Element Search"