2014-02-24 23 views
2

我是Selenium Ruby綁定的新手。我想知道文檔網站,我可以找到可用於Ruby驅動程序功能的選項。Selenium Ruby綁定功能文檔

我已經在網上搜索,發現大多是與Java相關的帖子:

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

我需要知道尤其是紅寶石等價物:「unexpectedAlertBehaviour」的能力。

在此先感謝。

添加的代碼:

代碼

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 

+0

這是語言無關。唯一的區別是*你如何傳遞能力。向我們展示迄今爲止您在構建驅動程序方面的情況。 – Arran

+0

@Arran,我在我的問題中添加了代碼。我之所以有點困惑的原因是,在上面的鏈接屬性是「ignoreProtectedModeSettings」,因爲在ruby綁定「ignore_protected_mode_settings」正在工作。 – Prasant

回答

3

從鏈接 - Read-write capabilities我找到的信息:

瀏覽器應該與之前未處理的警報做些什麼拋出UnhandledAlertException。可能的值是「接受」,「解僱」和「忽略」。

Key : unexpectedAlertBehaviour 
type : string ("accept"/"dismiss"/"ignore") 

你需要做的是:

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會給你Selenium::WebDriver::Remote::Capabilities類的實例。現在,如果您要設置任何自定義功能,則需要調用您從driver.capabilities調用中獲得的實例的方法#[]=

設置自定義一個後,你可以調用#to_json方法來查看所有與驅動程序設置的當前功能:

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"} 

如果你想,以確認你希望它是,如果自定義一個得到設定,通過調用方法#[]驗證相同:

puts ob[:unexpectedAlertBehaviour] # => dismiss 
+0

謝謝@Arup,您可以提供鏈接,以獲取有關Ruby綁定的API參考/教程.. – Prasant

+0

@ user3098734我已經爲您提供了我編寫此代碼的所有文檔。你能告訴我,你在找什麼具體的東西? –

+0

感謝您的信息。但是我有點困惑的原因是,在上面的鏈接屬性是「ignoreProtectedModeSettings」,因爲在ruby綁定「ignore_protected_mode_settings」中也在工作。 – Prasant

0

我得到了解決方案。我們必須在創建驅動程序的實例之前設置驅動程序的功能。下面的代碼是爲我工作:

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 

以上代碼處理保護模式,縮放設置(在某些情況下,硒是不能識別的對象)和Alert模式 - 這是接受模式錯誤。

希望,這將有利於其他:)

乾杯..

+0

我告訴過你 - 你做錯了。 [這裏](http://code.google.com/p/selenium/wiki/RubyBindings#Remote)是提示。無論如何,祝你好運。 :-) –

+0

謝謝奧雅納幫助:) – Prasant