Here is one option:
driver.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError
This will click OK on the alert if one is present, else it will fail gracefully (silently).
More Related Contents:
- Combining implicit wait and explicit wait together results in unexpected wait times
- Cannot call non W3C standard command while in W3C mode (Selenium::WebDriver::Error::UnknownCommandError) with Selenium ChromeDriver in Cucumber Ruby
- Pressing Ctrl + A in Selenium WebDriver
- setSpeed in Selenium WebDriver using Ruby
- Chrome 62 and Flash
- Net::ReadTimeout (Net::ReadTimeout) Selenium Ruby
- What is Ruby’s double-colon `::`?
- How to generate a random string in Ruby
- Code block passed to each works with brackets but not with ‘do’-‘end’ (ruby)
- Array#each vs. Array#map
- How do I copy a hash in Ruby?
- what is the functionality of “&: ” operator in ruby? [duplicate]
- Ruby Array Initialization [duplicate]
- What does ‘Monkey Patching’ exactly Mean in Ruby?
- Using ‘return’ in a Ruby block
- Ruby regular expression using variable name
- Best way to convert strings to symbols in hash
- When is `eval` in Ruby justified?
- How can I install a local gem?
- How to convert a string or integer to binary in Ruby?
- What does to_proc method mean in Ruby?
- When to use ‘self’ in Ruby
- Ruby: What does the comment “frozen_string_literal: true” do?
- How to create a private class method?
- ruby using the “&:methodname” shortcut from array.map(&:methodname) for hash key strings rather than methodname
- Fastest/One-liner way to list attr_accessors in Ruby?
- What will give me something like ruby readline with a default value?
- Is it possible to have class.property = x return something other than x?
- Functional code examples in ruby
- Ruby local variable is undefined