2012-11-16 28 views
0

我正在嘗試使用java中的selenium webdriver自動執行我的測試用例。它涉及基本認證對話框。爲了製作IE,Chrome,FF Compatible,使用相同的方法,我必須使用AutoIT我已經完成了IE和FF,但是對於Chrome而言,它不起作用。我正在使用AutoIT Window Info工具來查找類和控件名稱。但Chrome在這種情況下是非常不同的,任何人都可以幫忙?AutoIT對於Chrome無法正常工作 - Selenium WebDriver自動化的基本身份驗證對話解決方法

這裏是代碼工作的IE和FF

$classForBasicAuthenticationWindow = "[CLASS:#32770]" 
$username = "XXXXXX" 
$password = "XXXXXX" 

WinWait($classForBasicAuthenticationWindow,"",120) 
If WinExists($classForBasicAuthenticationWindow) Then 
    WinActivate($classForBasicAuthenticationWindow) 
    Send($username) 
    Send("{TAB}") 
    Send($password & "{Enter}") 
    EndIf 

這是FF類似,以上是IE

對於鉻我有這個迄今爲止寫的,如果你考慮window info的工具,你會了解在Chrome瀏覽器中彈出窗口不是一個不同的窗口。所以它變得有點複雜。反正這是我曾嘗試:

$classForBasicAuthenticationWindow = "[CLASS:Chrome_WidgetWin_1]" 
$username = "XXXXX" 
$password = "XXXXX" 

WinWait($classForBasicAuthenticationWindow,"",120) 
If WinExists($classForBasicAuthenticationWindow) Then 
WinActivate($classForBasicAuthenticationWindow) 
While 1 
    $isAuthenticationRequiredVisible = ControlGetHandle($classForBasicAuthenticationWindow, "", "[CLASS:ViewsTextfieldEdit; INSTANCE:2]") 
    If $isAuthenticationRequiredVisible <> "" Then 
    MsgBox($isAuthenticationRequiredVisible) 
    ExitLoop 
    EndIf 
WEnd 
ControlSend($classForBasicAuthenticationWindow, "", "[CLASS:ViewsTextfieldEdit; INSTANCE:2]", $username) 
EndIf 
+0

這已經在[另一個線程](http://stackoverflow.com/a/33918195/461099) – scottrudy

回答

2

你爲什麼不打開你的網址,以便(通過傳遞URL登錄憑證)

@driver.get "#{username}:#{password}@#{URL}" 

爲例

@driver.get "user:[email protected]" 
+1

回答嗨。我認爲它不適用於版本19之後的Chrome。對於IE,你需要註冊表黑客,無論如何你需要某種類型的autoIT機制。所以對於Chrome來說,我必須做一些不使用URL中的密碼和用戶名的東西。 還有一件事情假設爲例如這個方法對於後續的請求是有效的,我必須執行相同的過程還是我可以稍後直接使用它? –

+1

您可以直接使用。 – Amey

+0

感謝您的幫助 –

1

ControlSend方法使用窗口標題而不是窗口的類。 所以嘗試給窗口標題,因爲它出現在自動窗口信息工具。

下面給出的代碼適用於我。

$titleForBasicAuthenticationWindow = "Window Title As Given in Window Info Tool" 
$username = "XXXXX" 
$password = "XXXXX" 

WinWait($classForBasicAuthenticationWindow,"",120) 
If WinExists($classForBasicAuthenticationWindow) Then 
WinActivate($classForBasicAuthenticationWindow) 
ControlSend($classForBasicAuthenticationWindow, "", "[CLASS:ViewsTextfieldEdit; INSTANCE:2]", $username) 
EndIf 
+0

對於遲到的回覆感到抱歉。但在鉻的情況下,它是完全不同的情況下,就好像你打開窗口使用網絡驅動程序,這將是不同的,然後正常打開窗口..但讓我檢查一下,謝謝。 +1爲您提供幫助。 –

+1

你應該首先檢查它,而不是說它在chrome中是不同的case.I也是通過僅使用webdriver打開窗口在Chrome上測試它的。 –

+0

好的。阿比謝謝 –

相關問題