CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Retrieve value from executeScript

Open fabioel opened this issue 10 years ago • 2 comments

Hi!

I have been trying to retrieve a value from the executeScript and so far I have not been able to do so.

Here is my code:

seeOptionIsSelectedForSelect2(selector, optionText) {
      selector = this._getSelector(selector);
      this._optionIsSelectedForSelect2(selector, optionText)
      .then((data) => {
        console.log('The value is ' + data.value);
        assert.equal(data.value, true);
      });
    },
​
_optionIsSelectedForSelect2(selector, optionText) {
      let value = false;
      selector = this._getSelector(selector);
      value = this.executeScript(function(selector) {
       return jQuery(selector).val();
      }, selector);
      return isSelected;
}

The strange thing is that the data.value has the correct value, so my code actually works

I got the impression that the assert statement just does not work in the callback.

is this a problem with WebdriverIO?

fabioel avatar Mar 11 '16 14:03 fabioel

I got the impression that the assert statement just does not work in the callback.

Yes, it's not working. If you are writing that method in your own helper (or extending WebDriverIO helper) you should always return the promise so it can be added to promise chain. In your case you should change to

return this._optionIsSelectedForSelect2(...

DavertMik avatar Mar 13 '16 02:03 DavertMik

It works now! Thank you!

fabioel avatar Mar 14 '16 08:03 fabioel