我需要从then()返回一个值

时间:2019-09-01 12:54:10

标签: javascript node.js selenium selenium-webdriver promise

我需要从then()返回数组,但是idk如何做到这一点。

如果我尝试返回,则表明函数类型为void。 我尝试返回等待身体,但数组为空

const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const chromedriver = require('chromedriver');
let opt = new chrome.Options();
var result;
async function parser(shotLink, performerLogin) {
    let shots = [];
    let check = new Boolean;
    chrome.setDefaultService(new chrome.ServiceBuilder(chromedriver.path).build());
    opt.addArguments("chrome.switches", "--disable-extentions");
    opt.addArguments("user-data-dir=/home/mike/.config/google-chrome/");
    let driver = await new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).setChromeOptions(opt).build();
  await driver.get('link');
  await driver.findElement(webdriver.By.name('login')).sendKeys('log');
  await driver.findElement(webdriver.By.name('password')).sendKeys('pas', webdriver.Key.ENTER);
  await driver.get('lll' +performerLogin+ '/lll');
  await driver.findElements(webdriver.By.className('className')).then(function(elems){
    let count = 0;
    elems.forEach(function(elem){
      elem.getAttribute('href').then(function(value) {
        count++;
        shots.push(value)
      }).then(() => {
        if(count === elems.length) {
          return shots;
         } 
      })
    })
  })
}

此函数返回未定义

0 个答案:

没有答案