Home > Net >  Open one page per time for Selenium WebDriver for NodeJs
Open one page per time for Selenium WebDriver for NodeJs

Time:11-24

I am very new for Selenium WebDriver.

I have list of URL on the array and want to open the pages ( driver.get("url")) one by one. Here is an example:

urls.forEach( (url) => {
     driver.get(url);  //=> want to wait here until done.
     driver.getTitle(); //=> Here I want to get the title of current page before go to next url. 
}

Actually, currently seems it's ran synchronization with the Promise() - it's open multiple windows one time. I want to wait until the page is done and continue. Any idea for that?

CodePudding user response:

If you really want syncronous execution may be this will work better:

const {Builder} = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

(async function helloSelenium() {
const service = new chrome.ServiceBuilder('/Users/sanders/Desktop/chromedriver');
const driver = new Builder().forBrowser('chrome').setChromeService(service).build();    

const pages = ['https://google.com', 'https://abv.bg', 'https://facebook.com'];
for (page of pages){
await driver.get(page);
}
   

await driver.quit();
})();

CodePudding user response:

Nodejs seems not support Synchronization for Webdriver. I switched NodeJs to .Net and it's working fine now!

  • Related