0

我正在尝试在 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
4

3 回答 3

2

你为什么不打开你的 URL(通过在 URL 中传递登录凭据)

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

一个例子

@driver.get "user:pass@my.domain.com"
于 2012-11-16T22:01:54.413 回答
1

ControlSend 方法采用窗口标题而不是窗口的类。 因此,请尝试给出出现在 Autoit Window Info Tool 中的窗口标题。

下面给出的代码对我有用。

$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
于 2012-11-19T08:23:46.437 回答
0

对于 chrome,我尝试了所有方法,在基本 http 身份验证弹出窗口中输入凭据的最佳方法是通过 AutoIT。您只需要 sleep(25000) 在脚本的开头添加。确保 chrome 能够在 25 秒内打开该弹出窗口。如果没有,则增加睡眠时间。

于 2019-01-10T07:01:03.530 回答