This question already has an answer here:
selenium: ManagedPromise::32 {[[PromiseStatus]]: “pending”} message shown before navigating to the page
                                
                                    (1个答案)
                                
                        
                2年前关闭。
            
        

var personsWrapper = driver.findElement(By.className('_class1 _class2'));

personsWrapper.findElements(By.tagName('button')).then(function (persons_arr) {
    console.log("length:", persons_arr.length);
    persons_arr.forEach(function (p) {
        var x = p.getAttribute("value");
        console.log(x)
    })
});


尝试此操作时,我在控制台上得到一个ManagedPromise对象,而不是按钮的值-为什么?

最佳答案

方法getAttribute返回一个Promise,因此您首先需要解决它。

var webdriver = require('selenium-webdriver');
var By = webdriver.By;
var map = webdriver.promise.map;

var elems = driver.findElements(By.css("._class1._class2 button"));

map(elems, e => e.getAttribute("value"))
  .then(function(values) {
    console.log(values);
  });

08-07 21:56