-1

In following snippet would like to access value from outside of function and class

  driver.wait(until.elementLocated(By.xpath(path)), 2000).
        then(text => {
               text.getText().then(value => {
                        console.log("value:: " + value);
                     })

Would like to access value from outside the function and class

1 Answers1

0

In promise then() chain, the return value in the last then() will be recognized as the value of the whole then() chai. Therefore you need to return getText() in the last then() as following:

var textPromise = driver.wait(until.elementLocated(By.xpath(path)), 2000)
    .then(target => {
        return target.getText(); // return getText() in last then()
    });

Then you can consume the promise value via then() on the promise as following:

// to use the text at outside via then()
textPromise.then((text)=>{
    console.log('text: ' + text);
});
yong
  • 13,357
  • 1
  • 16
  • 27