Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
js accediendo al valor de retorno de la instrucción then()

Estoy creando una función que devuelve una serie de enlaces que están presentes en una página web. Más adelante, esta función se utilizará para recopilar más información en el sitio web. La función (cf. infra) funciona bien, pero no tengo ni idea de cómo acceder al hrefArray final. He intentado agregar varias declaraciones de retorno (dentro del bucle for y los diferentes then() pero sin éxito.

 const {Builder, By, Key, WebDriver, elementLocated, Browser, tagName} = require('selenium-webdriver'); var driver = new Builder().forBrowser('chrome').build() function findURLS(webpage){ console.log('Starting to look for URLS on webpage: ' + webpage) var result = driver.get(webpage) .then(res => { if(driver.getCurrentUrl() === webpage){ return true; } }).then(res => { console.log('Webpage opened') }).then(res => { var links = driver.findElements(By.tagName('a')) return links; }).then(links => { var hrefArray = [] function findhref(array, input){ var href = driver.wait(array[input].getAttribute('href')) return href; } for(i=0; i<links.length; i++){ findhref(links, i) .then(href => { hrefArray.push(href) if(hrefArray.includes(href)){ console.log("Href " + href + " succesfully pushed to hrefArray") return hrefArray; } else{ console.log("something went wrong while pushing the link to the hrefArray") } }) .then(hrefArray => { if(hrefArray.length == links.length){ console.log("hrefArray constructed successfully: " + hrefArray) return hrefArray //this is the final hrefArray that need to be returned after calling the findURLS(webpage) function } }) } //end of for statement }) .catch(error => { console.log(error) }) } function testexample(){ findURLS('https://dbrc.be/rechtspraak'); } testexample() ``
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda