From the link - Read-write capabilities I found information :
What the browser should do with an unhandled alert before throwing out the UnhandledAlertException. Possible values are "accept", "dismiss" and "ignore".
Key : unexpectedAlertBehaviour
type : string ( "accept"/"dismiss"/"ignore")
What you need to do is :
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.get "https://www.google.com/"
ob = driver.capabilities
ob[:unexpectedAlertBehaviour] = "dismiss" # or "accept"/"ignore"
driver.capabilities
will give you Selenium::WebDriver::Remote::Capabilities
class's instance. Now if you want to set any custom capabilities, you need to call the method #[]=
on the instance you got from the call driver.capabilities
.
After setting the custom one you can call #to_json
method to see all the current capabilities set with your driver :
puts ob.to_json
# >> { "browserName":"firefox","version":"21.0","platform":"WINNT","javascriptEnabled"
# >> :true,"cssSelectorsEnabled":true,"takesScreenshot":true,"nativeEvents":true,"rot
# >> atable":false,"handlesAlerts":true,"webStorageEnabled":true,"applicationCacheEna
# >> bled":true,"databaseEnabled":true,"locationContextEnabled":true,"browserConnecti
# >> onEnabled":true,"acceptSslCerts":true,"unexpectedAlertBehaviour":"dismiss"}
If you want to verify if the custom one got set, as you want it to be, verify the same by calling the method #[]
:
puts ob[:unexpectedAlertBehaviour] # => dismiss