OK so I have been banging my head against a wall trying to figure this out.
I am using node.js, selenium webdriver, and firefox.
I want to loop thru a list of URLs and save the resulting HTML to my file system.
The way I have it set up now it will loop thru all of the list but doesn't give me any output until the entire routine is completed and I only get data from the last element in the array, but I get the appropriate number of files.
An example of the code logic that I am using is:
var urlList = [link1,link2,link3];
var driver = new Builder().forBrowser('firefox').build();
function loopURL(){
var loopPromises = [];
urlList.forEach(url=>{
loopPromises.push(new Promise((resolve,reject)=>{
resolve(loadAndSaveResults(url))
})
return Promise.all(loopPromises);
}
function loadAndSaveResults(url){
return driver.wait(until.elementLocated(By.linkText(url)))
.then(_=> driver.get(url))
.then(_=> driver.getPageSource())
.then(pageString => driver.wait(writeToFile(pageString))
}
async function writeToFile(pageString){
await fs.writeFileSync(filepath,pageString);
{
driver.get('http://homepage/index.html')
.then(_=> loopURL())
.then(_=> driver.quit());
What am I missing?