Reputation: 2108
How do I identify an existing open Chrome Window with a specific url in its address bar, and open a new tab in that window using Selenium web driver in C#? All examples I see shows how to open new tabs in a window that is opened within Selenium ChromeDriver.
IWebDriver driver = null;
var chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
driver = new ChromeDriver(chromeDriverService);
List<string> tabs = new List<string>(driver.WindowHandles);
driver.WindowHandles always return the windows opened by the ChromeDriver. But, I am looking for all windows. As soon as the line that instantiates ChromeDriver is executed, a new window opens up. But, I need a new URL to be opened in a new tab in an existing window.
Upvotes: 0
Views: 2226
Reputation: 27496
WebDriver can't control browser windows that it didn't open. This is in part a security measure to prevent WebDriver-based malware. Additionally, to communicate with a browser instance, the browser must be listening on a port for incoming driver commands. Unless WebDriver started the browser, the browser has no way to know to listen on that port.
Upvotes: 8