Ruby “如何修复”;意外警报打开:{警报文本:}";错误

Ruby “如何修复”;意外警报打开:{警报文本:}";错误,ruby,selenium-webdriver,Ruby,Selenium Webdriver,我有一个与AngularJS合作的ruby项目,目前我正在将测试从Phantomjs转换为Headless chrome,我一直收到一个错误: Selenium::WebDriver::Error::UnhandledAlertError: unexpected alert open: {Alert text : } 这会在多个测试文件中发生。。 我试着添加 命令前的“接受警报{}”: #from find('.sp-advanced-configuration').

我有一个与AngularJS合作的ruby项目,目前我正在将测试从Phantomjs转换为Headless chrome,我一直收到一个错误:

Selenium::WebDriver::Error::UnhandledAlertError:
            unexpected alert open: {Alert text : }
这会在多个测试文件中发生。。 我试着添加

命令前的“接受警报{}”:

#from

find('.sp-advanced-configuration').click

#to
accept_alert{ find('.sp-advanced-configuration').click  } 

但接受

Failure/Error: accept_alert{ ... }

          Capybara::ModalNotFound:
            Unable to find modal dialog

以及

Selenium::WebDriver::Error::UnhandledAlertError:
            unexpected alert open: {Alert text : }
不知道还有什么好尝试的

/********************/

在进一步研究这一点之后,似乎在继续下一个测试之前,只要测试中还有未保存的更改,就会出现问题

有没有一种方法可以让你在每次测试中都接受这个,而不必添加

 after do 
    execute_script('window.onbeforeunload = undefined')
  end

在每个测试文件中?

您看到这种情况的原因是Poltergesit/PhantomJS用于自动接受意外的系统模态。selenium驱动程序不会这样做,因为您的测试应该主动接受或拒绝它。是
find('.sp advanced configuration')。单击打开警报框的操作?从你所犯的错误来看,我想不会。接收的块
accept_alert
必须是实际触发系统模式打开的块。这意味着您的代码可能需要

accept_alert { # action that triggers the alert }
find('.sp-advanced-configuration').click

谢谢你的回复,托马斯!不幸的是,这没有帮助。我已经进一步研究了这个问题,并在上面进行了解释。@PhilCollins您使用的是什么版本的水豚,您是否禁用了正常会话重置?在默认配置中,最新版本的Capybara应抑制警报。在尝试重置时处理警报。您可以将webdriver设置为接受所有警报。“忽略”设置将引发意外警报错误。请参阅ChromeOptions的“SetUnhandledPromptBehavior”: