All open Chrome windows using Selenium Chrome driver

旧城冷巷雨未停 提交于 2019-12-25 18:34:02

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/41177076/all-open-chrome-windows-using-selenium-chrome-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!