我正在嘗試使用Selenium的Chrome Webdriver和C#自動登錄網站。運行以下代碼將引發屏幕截圖1和2中列出的錯誤。我究竟做錯了什麼?谷歌搜索錯誤似乎沒有顯示任何相關的結果。Selenium Chrome Webdriver不能正常工作
using System.Drawing.Imaging;
using System.IO;
using OpenQA.Selenium.Chrome;
namespace WebDriverTest
{
class Program
{
static void Main(string[] args)
{
// Initialize the Chrome Driver
using (var driver = new ChromeDriver())
{
// Go to the home page
driver.Navigate().GoToUrl("https://twitter.com/");
// Get User Name field, Password field and Login Button
var userNameField = driver.FindElementById("usr");
}
}
}
}
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:61724/session/cc7bae393b288855ed8169dade774baa/element.
The status of the exception was ReceiveFailure, and the message was:
The underlying connection was closed: An unexpected error occurred on a receive.
我相信這是一個版本不匹配。什麼是您使用的鉻和鉻驅動程序的版本? 我會建議嘗試與鉻56和最新的鉻驅動程序2.28。看起來像57鉻可能有一些問題。 –