'How to open multiple web pages in chrome using Selenium Chrome Driver

I am using Selenium chrome driver to open URLs but when I try to open multiple sites, all are loading in a same tab one by one but I want to open each site in a separate chrome window.

IWebDriver driver;
ChromeDriverService chromeService = ChromeDriverService.CreateDefaultService();
chromeService.HideCommandPromptWindow = true;
ChromeOptions m_Options = new ChromeOptions();
m_Options.AddArgument("--disable-extensions");
driver = new ChromeDriver(chromeService, m_Options);
foreach (var url in urlList)
{
driver.Navigate().GoToUrl(url);
}

Can someone help me to identify the missing piece of code to open each URL in a new window.



Solution 1:[1]

In order to open each link in a new, separate tab you will have to open a new tab and switch to that tab before opening the next URL link.
Something like this:

foreach (var url in urlList)
{
    ((IJavaScriptExecutor)driver).ExecuteScript("window.open();");
    driver.SwitchTo().Window(driver.WindowHandles.Last());
    driver.Navigate().GoToUrl(url);
}

Be aware that if you are going to open too many windows without closing them this may cause memory lack so that it may case serious problems.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prophet