【问题标题】:Prevent ruby selenium-webdriver dismissing alerts when raising UnhandledAlertError防止 ruby​​ selenium-webdriver 在引发 UnhandledAlertError 时解除警报
【发布时间】:2012-04-05 23:03:16
【问题描述】:

查看 ruby​​ selenium-webdriver 的更改日志,我在 2.18.0 下找到了这一行:

  • Firefox 和 IE:
    • 如果在操作期间出现警报,则引发 UnhandledAlertError。未处理的警报也会被解除以减少重复异常。

在我看来,这是一个可怕的变化。我喜欢这个例外,但任何未处理的确认都会被驳回(返回假)。 我非常希望能够拯救异常并自己处理确认。

很遗憾,我在 selenium-webdriver gem 中找不到代码,因此我可以覆盖这一部分并摆脱关闭警报命令。

有什么办法解决这个问题(除了还原我的版本)?

提前致谢,

艺术

【问题讨论】:

    标签: ruby selenium webdriver


    【解决方案1】:

    我不能 100% 确定这就是您所追求的,但也许我会提供帮助。我理解您的问题的方式是您希望“强制”救援未处理的警报。

    由于超时而使用诸如查找元素函数之类的断言时,我正在使用以下代码重复搜索元素。

    !20.times { break if (selenium.is_visible(driver.find_element(:id, 'loginid')) rescue false ) ; sleep 1 }
    

    上面将循环 20 次(每次等待 1 秒)以尝试找到元素并在找到时中断。请注意,我还没有拯救它,因为将它放在开始/结束之间会更加健壮。像这样的东西..:

        begin           
    !20.times { break if (selenium.is_visible(driver.find_element(:id, 'loginid')) rescue false ) ; sleep 1 }
    
    [your executing code here]      .
          .
          .
    usr = driver.find_element(:id, 'loginid').click         
    usr = driver.find_element(:id, 'loginid').send_keys(username)
          .
          .
    rescue
          .
          .
    [your rescure code here]
          .
          .
    
    puts "____________________________________________________________________"
    puts "*** FATAL ERROR --> located at login area (username/password) ***"
    puts "Possible reasons for this error..:"
    puts "Invalid credentials * Cannot locate element id * "
    puts "____________________________________________________________________"
         .
    end
    

    希望有帮助!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    相关资源
    最近更新 更多