How do I confirm a javascript popup with Capybara?

前端 未结 8 970
梦谈多话
梦谈多话 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:02

    I had to use a sleep in the webkit test since it would fail everynow and then otherwise.

    Here is what I came up with after reading everyones posts:

    if page.driver.class == Capybara::Selenium::Driver
      page.driver.browser.switch_to.alert.accept
    elsif page.driver.class == Capybara::Webkit::Driver
      sleep 1 # prevent test from failing by waiting for popup
      page.driver.browser.accept_js_confirms
    else
      raise "Unsupported driver"
    end
    

提交回复
热议问题