[英]OpenQA.Selenium.WebDriverException
嗨,我有一個 c# window 表單應用程序,它在工作之前使用 selenium 打開邊緣,但幾個月后我收到此錯誤
An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
Additional information: A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:53335/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.
這是堆棧跟蹤
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
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.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options)
at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeDriverService service)
at XRF_Reader.DPRS_Main.XRF_Reader_Load(Object sender, EventArgs e) in c:\Users\****\Documents\projects\DPRS\DPRS\DPRS_Main.cs:line 75
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at MetroFramework.Forms.MetroForm.OnLoad(EventArgs e)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at MetroFramework.Forms.MetroForm.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我使用 Selenium webdriver - v 3.141.0 selenium webdriver IE v 3.141.0
這是我的代碼
var driverService = EdgeDriverService.CreateDefaultService();
EdgeOptions options = new EdgeOptions();
//var driver = new EdgeDriver(driverService);
edgeDriver = new EdgeDriver(driverService);
edgeDriver.Navigate().GoToUrl(Config.SpcUrl);
對於 Microsoft Edge 42.17134.1.0,MicrosoftEdge HTML 17.17134。
您可以從此鏈接下載 Release 17134 版本的 Edge WebDriver。
然后使用以下代碼使用 webDriver(將驅動程序路徑更改為您自己的):
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
namespace ecwebdriver
{
public class edgewebdriver
{
static void Main(string[] args)
{
var driverpath = @"C:\Windows\System32";
using (var driver = new EdgeDriver(driverpath))
{
// Navigate to Bing
driver.Url = "https://www.bing.com/";
// Find the search box and query for webdriver
var element = driver.FindElementById("sb_form_q");
element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
driver.Quit();
}
}
}
}
對於 Edge Chromium 版本(81.0.416.72(官方構建)(64 位))
從這里下載 Selenium 4.00-alpha05 的 C# 綁定或通過 Nuget ZEFE470A8E603AE877C8安裝它
從此頁面下載 Microsoft Edge 驅動程序的匹配版本。
然后,使用以下代碼(將驅動程序路徑和網站 url 更改為您自己的):
using OpenQA.Selenium.Edge;
using System.Threading;
namespace ecwebdriver
{
public class edgewebdriver
{
static void Main(string[] args)
{
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
edgeOptions.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
var msedgedriverDir = @"E:\webdriver";
var driver = new EdgeDriver(msedgedriverDir, edgeOptions);
driver.Navigate().GoToUrl("<website url>");
Thread.Sleep(3000);
driver.Close();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.