【问题标题】: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 Error - The HTTP request to the remote WebDriver timed out after 60 seconds 中描述的相同错误。

为了更好地理解问题,我需要创建一个重现错误的最小示例 - 一个 html 页面和一个使用 Selenium 打开它的控制台应用程序。

我的问题是:我如何准确地重现该错误,即创建一个有意触发此错误的实验程序?

编辑:如果有帮助,根据IEDriver. Download. HTTP request to the remote WebDriver server timed out after 60 seconds

这里的问题是,当IE在下载文件的过程中,浏览器的readyState永远不会从interactive变为complete

【问题讨论】:

    标签: 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();
        }
    

    结果如下:

    【讨论】:

      猜你喜欢
      • 2014-04-14
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      • 2018-11-15
      • 2017-09-03
      • 2018-03-22
      • 2019-02-21
      • 2017-05-06
      相关资源
      最近更新 更多