为什么访问URL时Selenium挂起?

问题描述 投票:0回答:1

我是Selenium的初学者。现在我有一个网站必须通过IE访问(Chrome或Edge根本不支持)。

由于微软在最新的Windows中删除了IE,该网站只能在Edge中通过兼容(IE)模式访问。

这是我的代码:

 var options = new InternetExplorerOptions
 {
     IgnoreZoomLevel = true, 
     IntroduceInstabilityByIgnoringProtectedModeSettings = true,
     EnsureCleanSession = true,
     PageLoadStrategy = PageLoadStrategy.Normal
 };
 
 IWebDriver driver = new InternetExplorerDriver($@"{AppDomain.CurrentDomain.BaseDirectory}\IEDriverServer.exe", options);
 driver.Manage().Window.Maximize();
 driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(60);
 driver.Navigate().GoToUrl("http://cced.com/cced.aspx");

 Debug.WriteLine(driver. Title);

程序运行后,打开Edge浏览器,成功通过IE模式访问网站首页。

但是,即使我在该行中添加断点

Debug.WriteLine(driver. Title);
它也永远不会运行。

1分钟后,报错如下:

OpenQA.Selenium.WebDriverException
  HResult=0x80131500
  Message=The HTTP request to the remote WebDriver server for URL http://localhost:9324/session/700c0df3-fcf5-459e-a9d9-0487cfd42d15/url timed out after 60 seconds.
  Source=WebDriver
  StackTrace:
   at OpenQA.Selenium.Remote.HttpCommandExecutor.<ExecuteAsync>d__34.MoveNext()
   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.<ExecuteAsync>d__10.MoveNext()
   at OpenQA.Selenium.WebDriver.<ExecuteAsync>d__63.MoveNext()
   at OpenQA.Selenium.Navigator.<GoToUrlAsync>d__7.MoveNext()
   at OpenQA.Selenium.Navigator.<>c__DisplayClass6_0.<<GoToUrl>b__0>d.MoveNext()
   at OpenQA.Selenium.Navigator.GoToUrl(String url)
   at ERPDownload.Form1.Form1_Load(Object sender, EventArgs e) in D:\Project\Test\Test\Form1.cs:line 28
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Control.CreateControl(Boolean ignoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

Inner Exception 1:
TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 60 seconds elapsing.

Inner Exception 2:
TimeoutException: The operation was canceled.

Inner Exception 3:
TaskCanceledException: The operation was canceled.

Inner Exception 4:
IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request.

Inner Exception 5:
SocketException: The I/O operation has been aborted because of either a thread exit or an application request.

有什么问题吗?

c# selenium-webdriver
1个回答
0
投票

我可以建议尝试其他方法来调试此代码,因为它似乎是在本地运行的,并且进程的环境配置中可能会出现一些问题。

首先检查主机 http://localhost:9324/session/700c0df3-fcf5-459e-a9d9-0487cfd42d15/url 中运行的进程是否确实可用。

如果是这样,请尝试增加服务的 http 请求的 maxTimeout。

如果两种方法都不起作用,请为整个块添加一个 try/catch 异常,并尝试更具体地了解出了什么问题。如果您发现另一个异常,请在此处发布。

© www.soinside.com 2019 - 2024. All rights reserved.