3

I am new to Selenium Ruby binding. I want to know the document website where I can find the options available for Ruby Driver capabilities.

I have searched the web and found mostly Java related posting:

https://code.google.com/p/selenium/wiki/DesiredCapabilities

I need to know the especially Ruby equivalent for : "unexpectedAlertBehaviour" capability.

Thanks in advance.

Added the code:

Code

def initialize(driverType)
begin
  cap = Selenium::WebDriver::Remote::Capabilities.ie(:ignore_protected_mode_settings=>true)
  @@driver =  Selenium::WebDriver.for driverType,:desired_capabilities=>cap 
  @@driver.manage.window.maximize
rescue Exception=>e
  puts e.message
end

end

Prasant
  • 105
  • 8
  • It's language agnostic. The only difference is *how* you pass in the capabilities. Show us what you've got so far in terms of how you are constructing the driver. – Arran Feb 24 '14 at 10:35
  • @Arran, I have added the code in my question. The reason why I was bit confuse is that in the link above the property is "ignoreProtectedModeSettings" where as in ruby binding "ignore_protected_mode_settings" is working. – Prasant Feb 24 '14 at 11:02

2 Answers2

4

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
Arup Rakshit
  • 109,389
  • 25
  • 234
  • 293
  • Thanks @Arup, Can you please provide link for API reference/ tutorial for Ruby binding.. – Prasant Feb 24 '14 at 11:14
  • @user3098734 I have given you all the documentation, from where I wrote this code. Would you tell me, what specific you are looking for ? – Arup Rakshit Feb 24 '14 at 11:24
  • Thanks for information. But the reason why I am bit confuse is that in the link above the property is "ignoreProtectedModeSettings" where as in ruby binding "ignore_protected_mode_settings" is also working. – Prasant Feb 24 '14 at 11:27
  • where did you set `ob[:unexpectedAlertBehaviour] = "dismiss"` ? It should work. I have tested – Arup Rakshit Feb 24 '14 at 11:44
  • Please find below code: def initialize(driverType) begin @@driver = Selenium::WebDriver.for driverType cap = @@driver.capabilities cap[:ignoreProtectedModeSettings] = true cap[:ignoreZoomSetting] = true cap[:unexpectedAlertBehaviour]="ignore" @@driver.manage.window.maximize rescue Exception=>e puts e.message end end – Prasant Feb 24 '14 at 11:46
  • It is throwing: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. – Prasant Feb 24 '14 at 11:47
  • @Prasant Got your point.. Here is a [answer](http://stackoverflow.com/questions/14952348/not-able-to-launch-ie-browser-using-selenium2-webdriver-with-java).. look into it. – Arup Rakshit Feb 24 '14 at 11:52
  • @Prasant I think you didn't code it will.. Have a look also here - http://code.google.com/p/selenium/wiki/RubyBindings#Remote – Arup Rakshit Feb 24 '14 at 11:57
  • My previous code was working, We can use both ignoreProtectedModeSettings and ignore_protected_mode_settings def initialize(driverType) begin cap = Selenium::WebDriver::Remote::Capabilities.ie(:ignoreProtectedModeSettings=>true) @@driver = Selenium::WebDriver.for driverType,:desired_capabilities=>cap @@driver.manage.window.maximize rescue Exception=>e puts e.message end end – Prasant Feb 24 '14 at 12:00
  • After adding my line you are in trouble ? – Arup Rakshit Feb 24 '14 at 12:02
  • I got the solution --- We have to set the capabilities before creating a driver object. Something like this in ruby: cap = Selenium::WebDriver::Remote::Capabilities.ie(:ignoreProtectedModeSettings=>true,:ignoreZoomSetting=>true,:unexpectedAlertBehaviour=>"accept") @@driver = Selenium::WebDriver.for driverType,:desired_capabilities=>cap – Prasant Feb 24 '14 at 12:21
0

I got the solution. We have to set the capabilities of the driver before creating an instance of it. Following code is working for me:

 def initialize(driverType)
begin
  cap = Selenium::WebDriver::Remote::Capabilities.ie(:ignoreProtectedModeSettings=>true,:ignoreZoomSetting=>true,:unexpectedAlertBehaviour=>"accept")

  @@driver =  Selenium::WebDriver.for driverType,:desired_capabilities=>cap 

  @@driver.manage.window.maximize
rescue Exception=>e
  puts e.message
end

end

Above code handles the Protection Mode, Zoom settings( in some case selenium is not able to identify objects) and the Modal alert - It is accepting the modal error.

Hope, this will be helpful for others :)

Cheers..

Prasant
  • 105
  • 8