selenium - 如何重现 Selenium 错误 - 对远程 WebDriver 的 HTTP 请求在 60 秒后超时
问题描述
我遇到了Selenium 错误中所述的相同错误 - 对远程 WebDriver 的 HTTP 请求在 60 秒后超时。
为了更好地理解问题,我需要创建一个重现该错误的最小示例 - 一个 html 页面和一个使用 Selenium 打开它的控制台应用程序。
我的问题是:我怎样才能重现这个错误,即创建一个有意触发这个错误的实验程序?
编辑:如果它有帮助,根据IEDriver。下载。对远程 WebDriver 服务器的 HTTP 请求在 60 秒后超时:
这里的问题是,当 IE 在下载文件的过程中,浏览器的 readyState 永远不会从 Interactive 变为 Complete
解决方案
您可以尝试添加一个包含按钮控件的网页,在按钮单击事件中,您可以调用 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();
}
结果是这样的:
推荐阅读
- angular - 如何在 Angular 中显示 @feathersjs-client 结果
- python-3.x - 如何更改此列表中元组每个元素中内容的位置?
- react-native - 在屏幕之间滑动不适用于反应原生,反应导航
- javascript - 如何使用 JavaScript API 在此处的地图中标记标记?
- javascript - 事件侦听器如何在单击时写入 console.log?
- python - Django - inspectdb - “models.FileField”显示为“models.CharField”
- c# - 将 CURL 调用转换为 C#
- magento - Magento 2.3 设置“InstallSchema”脚本未创建表
- c# - 旋转正在改变对象的 x 轴
- python - 当时只允许一个布尔值 True 吗?