Search code examples
rubyseleniumfirefoxcucumberwatir

Alert confirmed in Firefox but nothing happens after


Have a test that selects a radio button, and clicks a Delete button triggering a modal dialog/alert box pop up.

I'm using Cucumber so here's how the step works:

When /^i confirm the alert$/ do 
      Watir::Wait.until(timeout: 10) {@browser.alert.exists?}
      puts "i see the alert"
      @browser.alert.ok 
end

I put in that lazy debug step because I was thinking this may be a browser/driver issue.

I've had this work in Chrome but it's not an option for the certain environment I'm in for this particular script.

Firefox is my only option and here is what happens:

  • "i see the alert" is returned
  • the dialog is confirmed on

then I receive unable to locate alert (Watir::Exception::UnknownObjectException)

I'm on Firefox 45 ESR / Selenium Webdriver 3.0.5

Not sure if it's a Firefox/Selenium compatibility issue or not?

The application doesn't do anything after the OK button is clicked on the alert


Solution

  • Found the fix! And it was quite simple. I simply needed to send the Alert handling to Selenium instead of Watir.

    Instead of calling the Watir::Alert class:

    @browser.alert.ok 
    

    I just needed to let Selenium handle it. This is working in both FF and Chrome now:

    And(/^the user confirms the alert via selenium$/) do
        popup = @browser.driver.switch_to.alert
        popup.accept
    end