【问题标题】:How to reproduce the Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds如何重现 Selenium 错误 - 对远程 WebDriver 的 HTTP 请求在 60 秒后超时
【发布时间】:2023-03-19 15:55:01
【问题描述】:
【问题讨论】:
标签:
selenium
internet-explorer-11
【解决方案1】:
您可以尝试添加一个包含按钮控件的网页,在按钮单击事件中,您可以调用 Web API 来获取数据。在 Web API 方法中,添加 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();
}
结果如下: