How do I confirm a javascript popup with Capybara?

前端 未结 8 967
梦谈多话
梦谈多话 2020-12-08 01:55

I\'ve tried several examples found online, but with no luck. I am looking to confirm the confirm message of a delete link. The last attempt was the code below, but that re

8条回答
  •  眼角桃花
    2020-12-08 02:06

    I've had timing issues with browser dialogs in a CI environment so I'm polling for a dialog before accepting it:

    def accept_browser_dialog
      wait = Selenium::WebDriver::Wait.new(:timeout => 30)
      wait.until {
        begin
          page.driver.browser.switch_to.alert
          true
        rescue Selenium::WebDriver::Error::NoAlertPresentError
          false
        end
      }
      page.driver.browser.switch_to.alert.accept
    end
    

提交回复
热议问题