如何重现 Selenium 错误 - 对远程 WebDriver 的 HTTP 请求在 60 秒后超时
How to reproduce the Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds
我遇到了 中描述的相同错误。
为了更好地理解问题,我需要创建一个重现该错误的最小示例 - 一个 html 页面和一个使用 Selenium 打开它的控制台应用程序。
我的问题是:我该如何重现这个错误,即创建一个有意触发这个错误的实验程序?
编辑: 如果有帮助,根据 :
The problem here is that when IE is in the process of downloading a file, the readyState of the browser never moves from interactive to complete
您可以尝试添加一个包含按钮控件的网页,在按钮点击事件中,您可以调用一个网页API来获取数据。在webAPI方法中,添加Thread。 Sleep() 方法停止正在执行的线程一段给定的时间(超过请求时间)。然后,如果你使用Selenium WebDriver触发按钮点击事件,它会显示这个错误。
这样的代码:
mvc 视图中的代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
$(function () {
$("#buttonSearchPro").click(function () {
$.ajax({
url: "@Url.Action("GetData", "Home")",
async: false,
success: function (data) {
alert(data);
}
});;
});
});
</script>
<input type="button" id="buttonSearchPro" class="btn btnAction" value="Download" />
MVC 控制器中的代码:
public ActionResult GetData()
{
Thread.Sleep(70000000);
return Json("OK", JsonRequestBehavior.AllowGet);
}
控制台应用程序中的代码:
private const string URL = @"http://localhost:65330/Home/Index";
private const string IE_DRIVER_PATH = @"D:\Downloads\webdriver\IEDriverServer_x64_3.14.0";
static void Main(string[] args)
{
//EdgeWebDriver();
InternetExplorerTest();
}
public static void InternetExplorerTest()
{
try{
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = URL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true
};
var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
driver.Navigate();
//find the button and trigger click event.
driver.FindElementById("buttonSearchPro").Click() ;
driver.Close(); // closes browser
driver.Quit(); // closes IEDriverServer process
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("OK");
Console.ReadKey();
}
结果是这样的:
我遇到了 中描述的相同错误。
为了更好地理解问题,我需要创建一个重现该错误的最小示例 - 一个 html 页面和一个使用 Selenium 打开它的控制台应用程序。
我的问题是:我该如何重现这个错误,即创建一个有意触发这个错误的实验程序?
编辑: 如果有帮助,根据
The problem here is that when IE is in the process of downloading a file, the readyState of the browser never moves from interactive to complete
您可以尝试添加一个包含按钮控件的网页,在按钮点击事件中,您可以调用一个网页API来获取数据。在webAPI方法中,添加Thread。 Sleep() 方法停止正在执行的线程一段给定的时间(超过请求时间)。然后,如果你使用Selenium WebDriver触发按钮点击事件,它会显示这个错误。
这样的代码:
mvc 视图中的代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
$(function () {
$("#buttonSearchPro").click(function () {
$.ajax({
url: "@Url.Action("GetData", "Home")",
async: false,
success: function (data) {
alert(data);
}
});;
});
});
</script>
<input type="button" id="buttonSearchPro" class="btn btnAction" value="Download" />
MVC 控制器中的代码:
public ActionResult GetData()
{
Thread.Sleep(70000000);
return Json("OK", JsonRequestBehavior.AllowGet);
}
控制台应用程序中的代码:
private const string URL = @"http://localhost:65330/Home/Index";
private const string IE_DRIVER_PATH = @"D:\Downloads\webdriver\IEDriverServer_x64_3.14.0";
static void Main(string[] args)
{
//EdgeWebDriver();
InternetExplorerTest();
}
public static void InternetExplorerTest()
{
try{
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = URL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true
};
var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
driver.Navigate();
//find the button and trigger click event.
driver.FindElementById("buttonSearchPro").Click() ;
driver.Close(); // closes browser
driver.Quit(); // closes IEDriverServer process
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("OK");
Console.ReadKey();
}
结果是这样的: