2014-05-17 23 views
0

最近,我正在使用紅寶石中的appium + selenium進行移動自動化。但由於以下問題而停止:每次發生異常時,硒驅動程序都會自動退出(移動應用程序已關閉)。這會導致在設法解救異常後,下面的代碼訪問驅動程序將失敗。
例如ruby​​ selenium-webdriver在異常被解救前退出

begin 
    @driver.find_element(:xpath, "//window[1]/button[27]") 
rescue 
    @driver.find_element(:xpath, "//window[1]/navigationBar[1]/button[2]").click 
end 

有沒有人有這個問題? 。

回答

0

http://www.ruby-doc.org/core-2.1.1/doc/syntax/exceptions_rdoc.html「默認情況下StandardError的和它的子類獲救您可以通過搶救後列出他們搶救一組特定的異常類(及其子類)的:

begin 
    # ... 
rescue ArgumentError, NameError 
    # handle ArgumentError or NameError 
end 

我假設你正在等待如ElementNotVisibleException。因此,在rescue之後添加例外類型,例如rescue ElementNotVisibleException