【发布时间】:2017-02-22 13:58:22
【问题描述】:
我正在尝试使用 Selenium 的 Chrome Webdriver 和 C# 自动登录网站。运行以下代码会引发屏幕截图一和二中列出的错误。我究竟做错了什么?谷歌搜索错误似乎没有显示任何相关结果。
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.
【问题讨论】:
-
我相信这是版本不匹配。您使用的是什么版本的 chrome 和 chrome 驱动程序?我建议尝试使用最新的 chrome 56 和 chrome driver 2.28。看起来 57 chrome 可能有问题。
标签: c# .net selenium selenium-chromedriver