Skip to main content
 首页 » 编程设计

selenium之使用Selenium的Chrome驱动程序错误:无法发现打开的页面

2024年10月01日24虾米哥

运行Selenium测试时出现与Chrome驱动程序相关的错误。错误消息是“无法发现打开的页面。”直到昨天晚上,Selenium测试都运行良好。该问题似乎是在前一天重新启动服务器后开始的。我无法在本地机器上重现此错误。从服务器上的命令行运行Selenium测试确实会打开Chrome浏览器,但会导致相同的错误。有任何想法吗?

失败的行:

chromeDriver = new OpenQA.Selenium.Chrome.ChromeDriver(externalDriverPath); 

错误消息和堆栈跟踪:

unable to discover open pages (Driver info: chromedriver=2.1,platform=Windows NT 6.1 SP1 x86_64) at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options) at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory) at SeleniumTests.BaseTest.SetupBrowsers()



创建ChromeDriver实例时,将显示一个控制台窗口。出现错误的服务器似乎引用了未实现的内容。

服务器上的ChomeDriver输出,错误为:

Started ChromeDriver (v2.1) on port 2984 [4700:4292:0108/111503:ERROR:gpu_info_collector_win.cc(102)] Can't retrieve a va lid WinSAT assessment. [4700:4292:0108/111503:ERROR:chrome_views_delegate.cc(176)] NOT IMPLEMENTED [4700:4292:0108/111503:ERROR:desktop_root_window_host_win.cc(746)] NOT IMPLEMENT ED [0108/111504:ERROR:gl_surface_egl.cc(132)] eglInitialize failed with error UNKNO WN [0108/111504:ERROR:gl_surface_win.cc(97)] GLSurfaceEGL::InitializeOneOff failed.



我的PC上的ChomeDriver输出正常运行:

Started ChromeDriver (v2.1) on port 18786 [884540:883760:0108/114010:ERROR:gpu_info_collector_win.cc(102)] Can't retrieve a valid WinSAT assessment. [884992:884996:0108/114010:ERROR:base_feature_provider.cc(122)] manifestTypes: A llowing web_page contexts requires supplying a value for matches. [885232:885236:0108/114011:ERROR:base_feature_provider.cc(122)] manifestTypes: A llowing web_page contexts requires supplying a value for matches. [884540:883760:0108/114011:ERROR:base_feature_provider.cc(122)] manifestTypes: A llowing web_page contexts requires supplying a value for matches. [0108/114011:ERROR:gl_surface_egl.cc(131)] eglInitialize failed with error UNKNO WN [0108/114011:ERROR:gl_surface_win.cc(54)] GLSurfaceEGL::InitializeOneOff failed.

请您参考如下方法:

您正在使用版本过旧的ChromeDriver。您的第一个通话端口应该是对其进行更新here

我非常怀疑问题是服务器上的Chrome已更新,而ChromeDriver v2.1并没有support任何最新版本的Chrome。