问题描述
如何识别现有的打开的Chrome窗口,该窗口在其地址栏中具有特定的网址,并使用C#中的Selenium Web驱动程序在该窗口中打开一个新标签?我看到的所有示例都显示了如何在Selenium ChromeDriver中打开的窗口中打开新标签.
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始终返回由ChromeDriver打开的窗口.但是,我正在寻找所有窗户.一旦执行实例化ChromeDriver的行,就会打开一个新窗口.但是,我需要在现有窗口的新标签页中打开一个新URL.
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.
推荐答案
WebDriver无法控制未打开的浏览器窗口.这部分是为了防止基于WebDriver的恶意软件的安全措施.此外,要与浏览器实例进行通信,浏览器必须在端口上侦听传入的驱动程序命令.除非WebDriver启动浏览器,否则浏览器将无法知道在该端口上进行监听.
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.
这篇关于使用Selenium Chrome驱动程序的所有打开的Chrome窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!