1

I think I setup my driver.get(site) calls wrong as they're all executing at the same time. I'm trying to have selenium visit a site, do some logic, pause for a bit, then start over by visiting a different site. Unfortunately, this is all happening at the same time right now, causing the browser to redirect to the next site in the array as soon as the page loads.

let webdriver = require("selenium-webdriver");
    let sites = [
    'https://www.site1.com'
    , 'https://www.site2.com'
    , 'https://www.site3.com'
];
let driver = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome' }).build();
sites.forEach(site => {
    driver.get(site).then(x => { 
        //   perform a mixture of send keys, clicks, and a mandatory delay
        Promise.all([
            promise1
            , promise2
            , driver.sleep(1000)
        ]).then(y => {

        }).catch(err => {

        })
    })
})
Isaac L
  • 73
  • 1
  • 5

1 Answers1

0

Use recursive approach and call the function from .then(y => {})

let webdriver = require("selenium-webdriver");
let sites = [
    'https://www.site1.com'
    , 'https://www.site2.com'
    , 'https://www.site3.com'
];
let driver = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome' }).build();

function doCheck( sites, ind ) {
    driver.get(sites[ind]).then(x => { 
        //   perform a mixture of send keys, clicks, and a mandatory delay
        Promise.all([
            promise1
            , promise2
            , driver.sleep(1000)
        ]).then(y => {
            if (sites.indexOf(sites[ind++]) !== -1){
                doCheck(sites, ind++);
            }
        }).catch(err => {

        })
    })  
}

doCheck( sites, 0 );