johnnyshrewd
johnnyshrewd

Reputation: 1180

How to wait for an element to be visible in CUCUBER JS?

I am getting :

NoSuchElementError: no such element: Unable to locate element

My wait function is not waiting at all. As soon as it gets to that step it fails without waiting for the set wait time.

in my world.js i define my drive

var driver = buildChromeDriver();
  ...
  var World = function World() {
  ...
  this.driver = driver;
}

This is on of my steps :

  this.Then(/^xxxxx$/, function () {
  this.driver.wait(function () {
      return this.driver.findElement({ xpath: props.woocomerceSelectors.viewCart }).isDisplayed();
  }, 4000);});

Upvotes: 0

Views: 1133

Answers (1)

kfairns
kfairns

Reputation: 3057

The wait will loop through until a non-false answer is returned within the loop.

What your code is doing at the moment is returning a pending promise, which is not false, therefore will not loop through.

If you grab the stuff from this promise, and return whether it's equal to true, then you should have more luck.

this.Then(/^xxxxx$/, function () {
    this.driver.wait(function () {
        return this.driver.findElement({xpath: props.woocomerceSelectors.viewCart}).isDisplayed()
            .then(function (isDisplayed) {
                return isDisplayed == true;
            });
    }, 4000);
});  

I hope this helps.

Upvotes: 1

Related Questions