【发布时间】:2012-11-05 13:14:24
【问题描述】:
我正在尝试在 java 中使用 selenium webdriver 自动化我的测试用例。它涉及基本身份验证对话框。为了使用相同的方法使 IE、Chrome、FF 兼容,我必须使用 AutoIT 我已经完成了 IE 和 FF,但对于 Chrome,它不起作用。我正在使用AutoIT Window Info 工具来查找类和控件名称。但是在这种情况下,Chrome 完全不同,有人可以帮忙吗?
这是工作 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
到目前为止,对于 Chrome,如果您考虑使用 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
【问题讨论】:
-
这个问题已经在another thread回答了
标签: selenium selenium-webdriver autoit browser-automation