我正在嘗試使用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
這已經在[另一個線程](http://stackoverflow.com/a/33918195/461099) – scottrudy