试图使用C#中的Selenium在现有的Chrome浏览器上运行测试。我正在我的macbook上做这个。
问题是,c#代码没有用指定的端口与浏览器连接。相反,代码一直打开自己的浏览器。运行多少个chrome实例并不重要。它只应该连接到打开端口的端口,而不是超时,并且似乎在寻找与我指定的端口不同的端口。
步骤:
我使用终端手动打开带有调试端口的chrome浏览器:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9014然后,将C#代码附加到浏览器并运行一个简单的Selenium脚本:
var chromeDriverLocation = "/Users/jb/Projects/fjsdlfsdf/fjsdlfsdf/bin/Debug";
var options = new ChromeOptions();
options.DebuggerAddress = "localhost:9014"; // specifying the port of the existing browser
Driver = new ChromeDriver(chromeDriverLocation, options);
Driver.Navigate().GoToUrl("https://google.com");但是我得到了这个错误,它指的是一个完全不同的端口:
OpenQA.Selenium.WebDriverException
The HTTP request to the remote WebDriver server for URL http://localhost:53678/session timed out after 60 seconds.发布于 2021-01-19 13:38:37
试着先关闭所有的chrome浏览器实例
在chrome中,即使您给出标志-调试器地址,如果任何进程仍然保持该端口处于打开状态,它也可能不会使用该调试器端口启动chrome。它也不会抛出任何错误。
因此,通过在任何浏览器或选项卡中打开http://localhost:9014 来验证在该端口中确实打开了chrome。
如果它不打开,就意味着chrome没有使用该调试端口启动。关闭所有chrome实例或重新启动系统后,使用不同的端口作为调试器地址
还要查看端口是否在使用,并关闭它(windows)。
netstat -ano | findstr :PORT
kill PIhttps://stackoverflow.com/questions/65792162
复制相似问题