Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SeleniumWebDriver中使用Ruby时,如何接受javascript警报_Javascript_Ruby_Selenium_Selenium Webdriver - Fatal编程技术网

在SeleniumWebDriver中使用Ruby时,如何接受javascript警报

在SeleniumWebDriver中使用Ruby时,如何接受javascript警报,javascript,ruby,selenium,selenium-webdriver,Javascript,Ruby,Selenium,Selenium Webdriver,我试图在弹出的JavaScript警报中单击OK以删除页面上的元素。我有以下资料: assert element_present?(:css, "#add_foods_1 > table > tbody > tr > td.cf.cc2 > a.track_remove") @driver.find_element(:css, "#add_foods_1 > table > tbody > tr > td.cf.cc2 > a.trac

我试图在弹出的JavaScript警报中单击OK以删除页面上的元素。我有以下资料:

assert element_present?(:css, "#add_foods_1 > table > tbody > tr > td.cf.cc2 > a.track_remove")
@driver.find_element(:css, "#add_foods_1 > table > tbody > tr > td.cf.cc2 > a.track_remove").click
assert_equal "This will delete this food from your foods eaten today.  Click OK to continue or Cancel to return.", close_alert_and_get_its_text() 
调用
close\u alert\u和\u get\u其\u text()的定义代码如下:

def close_alert_and_get_its_text(how, what)
  alert = @driver.switch_to().alert()
  alert_text = alert.text
  if (@accept_next_alert) then
    alert.accept()
  else
    alert.dismiss()
  end
  alert_text
  ensure
    @accept_next_alert = true
  end

我对如何点击OK关闭警报感到困惑。警报中有“确定”和“取消”。

这可能会有所帮助?谢谢!我把它改为@driver.switch_改为.alert.accept,现在工作正常。再次感谢!