Selenium WebDriver FindElement(noSuchElementId)抛出TimeoutException而不是NoSuchElementException

时间:2013-12-04 19:09:23

标签: c# selenium webdriver

IE 11和Selenium 2.37试图获取带有无效elementId的元素文本:

TimeSpan pageLoadTimeout = new TimeSpan(HOURS, MINUTES, m_WebPageSettings.PageLoadTimeoutSeconds);

InternetExplorerOptions IeOptions = new InternetExplorerOptions()
{
    InitialBrowserUrl = m_WebPageUrl,
    IntroduceInstabilityByIgnoringProtectedModeSettings = true,
    BrowserAttachTimeout = pageLoadTimeout,
    RequireWindowFocus = true,
    IgnoreZoomLevel = true
};

m_Driver = new InternetExplorerDriver(AppDomain.CurrentDomain.BaseDirectory, IeOptions);

m_Driver.Manage().Timeouts().SetPageLoadTimeout(pageLoadTimeout);
m_Driver.Manage().Timeouts().SetScriptTimeout(pageLoadTimeout);            
m_Driver.Manage().Timeouts().ImplicitlyWait(pageLoadTimeout);

result = m_Driver.FindElement(By.Id(elementId)).Text;

引发此异常:

OpenQA.Selenium.WebDriverException was caught
  HResult=-2146233088
  Message=The HTTP request to the remote WebDriver server for URL http://localhost:56732/session/4d8e064a-90b7-45f2-a7bc-42c7845534a4/element timed out after 60 seconds.
  Source=WebDriver

堆栈跟踪:

 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.RemoteWebDriver.FindElement(String mechanism, String value) 
       at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id) in 
       at OpenQA.Selenium.By.<>c__DisplayClass2.<Id>b__0(ISearchContext context) 
       at OpenQA.Selenium.By.FindElement(ISearchContext context) 
       at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) 
       at Alpha.Dsm.WebPage.Utilities.WebPageInteractor.GetTableCellString(String cellId) 

内部异常:

  InnerException: System.Net.WebException
       HResult=-2146233079
       Message=The operation has timed out
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)

为什么它不会抛出OpenQA.Selenium.NoSuchElementException,我该怎么做呢?

0 个答案:

没有答案