Retrieve value from executeScript
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?
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(...
It works now! Thank you!