【问题标题】:Selenium Not Catching Timeout ExceptionSelenium 未捕获超时异常
【发布时间】:2017-06-02 00:39:08
【问题描述】:

我刚刚开始使用 Selenium,到目前为止非常喜欢它,但遇到了一个让我发疯的问题!无论我做什么,我似乎都无法捕捉到“OpenQA.Selenium.WebDriverTimeoutException 未被用户代码处理”异常。

我使用的代码是:

   Private Sub WaitForLoad(ByRef driver As PhantomJSDriver, ByVal Timeout As TimeSpan, ByVal FindField As IWebElement)
    Try
        Dim wait As WebDriverWait = New WebDriverWait(driver, Timeout)
        wait.Until(ExpectedConditions.ElementToBeClickable(FindField))
    Catch ex As OpenQA.Selenium.WebDriverTimeoutException
        MessageBox.Show("1")
        Throw New Exception(ex.Message)
    Catch ex As WebDriverException
        MessageBox.Show("2")
        Throw New Exception(ex.Message)
    Catch ex As System.TimeoutException
        MessageBox.Show("3")
        Throw New Exception(ex.Message)
    Catch ex As Exception
        MessageBox.Show("4")
        Throw New Exception(ex.Message)
    End Try
End Sub

我只是将消息框放在那里,因为我一直在尝试捕获所有异常类型以检查哪种异常类型会真正捕获它,但没有一个会。

我正在调用函数,例如

WaitForLoad(driver, WaitTimeout, driver.FindElementByName("search"))

我在 SO 上看到了一些与此类似的其他问题,但所有问题的答案都是“添加 WebDriverTimeoutException”,我到目前为止还没有运气。希望在我再花几个小时解决这个问题之前,其他人已经解决了这个问题!?!

【问题讨论】:

    标签: vb.net selenium selenium-webdriver exception-handling phantomjs


    【解决方案1】:

    通过 Visual Studio 启用“启用非托管代码调试”后,此问题已解决。

    【讨论】:

      猜你喜欢
      • 2016-07-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      • 2011-11-02
      • 2021-02-25
      • 2017-04-19
      相关资源
      最近更新 更多