【问题标题】:Handling Windows authentication pop up处理 Windows 身份验证弹出窗口
【发布时间】:2013-01-31 08:15:12
【问题描述】:

以下是我的 AutoIt 脚本 (UI3_Authentication.au3),用于处理 Windows 身份验证弹出窗口。

AutoItSetOption("WinTitleMatchMode","2")  
WinWait("Authentication Required")   
$title = WinGetTitle("Authentication Required") ; retrives whole window title   
$UN=WinGetText($title,"User Name:")  
ControlSend($title,"",$UN,"test");Sets Username  
$PWD=WinGetText($title,"Password:")  
Send("{TAB 1}")  
ControlSend($title,"",$PWD,"test1234");Sets PWD  
Send("{ENTER}")  

下面是我对上述 AutoIt exe 文件的 Selenium 代码调用。

package tests;

import java.io.IOException;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.firefox.FirefoxDriver;  

public class Handling_Windows_Based_Prompt {

public static void main(String[] args) throws IOException{  
WebDriver c1 = new FirefoxDriver();  
c1.get(“http://www.test.com”);  
        Runtime.getRuntime().exec("C:\\POM_Newdemo\\EF_Automation_Demo\\UI3_Authentication.exe");

}  
}

当我运行上述 Selenium 文件时,它会打开页面并弹出身份验证。但它没有插入用户名和密码;它改为等待用户输入。

【问题讨论】:

    标签: selenium selenium-webdriver autoit


    【解决方案1】:

    我解决了这个问题。 其实,这是我的错。之前我的代码是这样的:

    c1.get(“http://www.test.com”);  
        Runtime.getRuntime().exec("C:\\POM_Newdemo\\EF_Automation_Demo\\UI3_Authentication.exe");
    

    我在 get() 之前添加了 autoit 代码,如下所示,它起作用了:

    Runtime.getRuntime().exec("C:\\POM_Newdemo\\EF_Automation_Demo\\UI3_Authentication.exe");
    c1.get(“http://www.test.com”);
    

    【讨论】:

      【解决方案2】:

      这适用于我的 ChromeDriver。希望对你有帮助

      WinWait("data:, - Google Chrome","","10") ; this is the name of the window, according to AUTOIT v3 window info
      If WinExists("data:, - Google Chrome","") Then
      WinActivate("data:, - Google Chrome") ; set control to the window for proxy authentication
      Send("putUsernameHere{TAB}") ; send username and press TAB
      WinActivate("data:, - Google Chrome") ; again set control to our window, in case that we have clicked somewhere else
      Send("putPasswordHere{ENTER}") ; send the password and press enter
      EndIf
      

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题。如果 AutoIt 在“开放”桌面上运行,它可以很好地与 selenium 配合使用。 如果我使用带有打开会话的虚拟机(查看正在发生的事情),即使最小化,它也可以正常工作,但是如果我关闭远程桌面(会话结束),AutoIt 脚本会显示成功但什么也不做。

        “解决方案”是通过将虚拟机与 TightVNC 连接来保持虚拟机“打开”。即使关闭窗口,VNC 也会保持登录状态,AutoIt 可以正常工作。

        希望这些信息对您有所帮助。这不是一个解决方案,但也许您可以解决它。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-12-24
          • 1970-01-01
          • 1970-01-01
          • 2017-04-23
          • 1970-01-01
          • 1970-01-01
          • 2020-11-25
          • 2016-05-11
          相关资源
          最近更新 更多