【问题标题】:AutoIT For Chrome Not Working - Basic Authentication Dialog workaround for Selenium WebDriver AutomationAutoIT For Chrome Not Working - Selenium WebDriver Automation 的基本身份验证对话框解决方法
【发布时间】: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

【问题讨论】:

标签: selenium selenium-webdriver autoit browser-automation


【解决方案1】:

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

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

一个例子

@driver.get "user:pass@my.domain.com"

【讨论】:

  • 嗨。我认为在 19 版之后它在 chrome 中不起作用。对于 IE,您需要注册表 hack,无论如何您需要某种 autoIT 机制。因此,对于 chrome,我必须做一些不在 url 中使用密码和用户名的事情。假设还有一件事,例如此方法适用于后续请求,我必须执行相同的程序还是以后可以直接使用它?
【解决方案2】:

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

【讨论】:

  • 抱歉回复晚了。但是对于 chrome,情况完全不同,就好像您使用 Web 驱动程序打开窗口一样,它会与正常打开窗口不同.. 但让我检查一下,谢谢。 +1 为您提供帮助。
  • 你应该先检查它,而不是说在 chrome 中它是不同的大小写。我也通过仅使用 webdriver 打开窗口在 chrome 上对其进行了测试。
【解决方案3】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 2017-11-16
    • 2022-08-19
    相关资源
    最近更新 更多