Selenium Webdriver times out on IE 11

本文关键字:IE on out Webdriver times Selenium | 更新日期: 2023-09-27 18:06:28

我在IE 11 windows 7上运行Selenium WEbdriver有问题。发送键太慢了。我已经为IE下载了最新的web驱动程序,但它仍然不起作用。下面是我一直收到的超时异常:

Test Name:  TestInInternetExplorer
Test FullName:  TravelTest_1.UnitTest1.TestInInternetExplorer
Test Source:    c:'Users'Documents'Visual Studio 2013'Projects'TravelTest_1'TravelTest_1'UnitTest1.cs : line 34
Test Outcome:   Failed
Test Duration:  0:01:36.7213961
Result Message: 
Test method TravelTest_1.UnitTest1.TestInInternetExplorer threw exception: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:14927/session/41c432de-a158-4a14-bbc0-38a21cd67582/element/c9da6f89-09e9-4da9-a84a-ea262762491d/value timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out
Result StackTrace:  
at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
 --- End of inner exception stack trace ---
    at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
   at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebElement.SendKeys(String text)
 --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at OpenQA.Selenium.Support.PageObjects.WebDriverObjectProxy.InvokeMethod(IMethodCallMessage msg, Object representedValue)
   at OpenQA.Selenium.Support.PageObjects.WebElementProxy.Invoke(IMessage msg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at OpenQA.Selenium.IWebElement.SendKeys(String text)
   at TravelTest_1.CreateTANonProxy_Domestic.FillGeneralInfo() in c:'Users'Documents'Visual Studio 2013'Projects'TravelTest_1'TravelTest_1'CreateTANonProxy_Domestic.cs:line 112
   at TravelTest_1.UnitTest1.CreateTADraft(IWebDriver driver) in c:'Users'Documents'Visual Studio 2013'Projects'TravelTest_1'TravelTest_1'UnitTest1.cs:line 123
   at TravelTest_1.UnitTest1.TestInInternetExplorer() in c:'Users'Documents'Visual Studio 2013'Projects'TravelTest_1'TravelTest_1'UnitTest1.cs:line 44

我的代码如下:

InternetExplorerOptions options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
    using (IWebDriver IEDriver = new InternetExplorerDriver(options))
    {
        Console.WriteLine("Executed in IE 11");
        CreateTADraft(IEDriver);
        Console.WriteLine("Draft saved in IE 11");
    }

下面是有问题的代码:

count = counter;
     if (count.Equals(counter))
     {
         count = count + 1;
         y = count;
     }
     try 
     {
         using (var context = new MainDataContext(Properties.Settings.Default.ConnectionString))
         {
             foreach (var e in context.TARequestForm.Where(x => x.Id == y))
             {
                 String contact = e.Phone;
                 String purpose = e.Purpose;
                 purposeBox.Clear();
                 purposeBox.SendKeys(purpose);
                 contactBox.Clear();
                 contactBox.SendKeys(contact);
             }
         }
     }catch(WebDriverTimeoutException e)
     {
         Console.WriteLine(e);
         throw e;
     }

我不确定我能做什么变通办法了。顺便说一句,这实际上在IE中运行,它只是在发送密钥的中间停止。谢谢。

Selenium Webdriver times out on IE 11

在代码中添加了以下内容:

    InternetExplorerOptions options = new InternetExplorerOptions();
    options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
    options.RequireWindowFocus = true;

这加快了我的sendkeys。RequireWindowFocus解决了我的问题。由于@Kolichikov