driver.findElements(By.css("div#box-campaigns.box s.regular-price")) .then(result => result.map(z => z.getCssValue(["color"]))) .then(res =>Promise.all(res) .then(z => console.log(z)) ); 

you will need to compare the value of Z with the result of another promise, but how to get this value so that you can work with it?

Ps. I had no business with promises before, but I really want to figure it out

Reported as a duplicate at Grundy. javascript Aug 31 '18 at 10:21 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    You can put another promise in the last then:

     driver.findElements(By.css("div#box-campaigns.box s.regular-price")) .then(result => result.map(z => z.getCssValue(["color"]))) .then(res => Promise.all(res)) .then(z => { // Вы хотите работать с полученой z, она доступна тут(в этом теле функции) // Вот пример как использовать промис с использованием z myPromise(z).then(result => { // результат промиса }) }); 

    You can write a function that returns a promise with z:

     function getZ () { return driver.findElements(By.css("div#box-campaigns.box s.regular-price")) .then(result => result.map(z => z.getCssValue(["color"]))) .then(res => Promise.all(res)) } getZ().then(z => { // тут доступна z }); 

    Here is a good promise.

    • I wrote it wrong there, the second one should definitely work, just in then write one more promise - Ilya Zelenko
    • outside, you can, for example, write at least to the global window object, but there it will be available only after the promise is completed. That is, you refer to the variable before the promise is executed, it will be undefined. If you need to get the value of z not only in one place, then you can make a function (updated answer) that returns a promise with z. - Ilya Zelenko
    • I try to compare the values ​​obtained by the promises from two different pages. Except how to save one of the values, I have not thought of anything yet. If there are other options, then tell me. - Igor Truskov
    • This is another question. To transfer data to another page, you can use localStorage. First you do the promis on one page, write the result to the local storage, then you need to somehow track that it has changed on another page, the easiest option is to make setInterval and check for change there, if it has, then run the second promise. There is another option to track the following storage: stackoverflow.com/a/50768359/5286034 . Here is a better example. - Ilya Zelenko
    • your second option works! now how to compare the results of the two promises? - Igor Truskov