【问题标题】:Handling windows security popup while web page loading using Selenium and AutoIt使用 Selenium 和 AutoIt 在网页加载时处理 Windows 安全弹出窗口
【发布时间】:2011-11-03 14:13:53
【问题描述】:

我有一个基于 Web 的应用程序,当第一个网页开始加载时会显示 Windows 安全弹出窗口,并且只有在我们提供登录凭据后页面才完成加载。

我编写了以下脚本,但它不会在selenium.open("/faces/Main"); 之后进入下一个代码行,最终失败并显示默认超时错误消息。

结果控制台:

Timeout 30000ms

Selenium1 代码:

package first;

import java.io.IOException;

import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;



public class Auth_assign {

private Selenium selenium;

   @BeforeClass
   public void setup() 
   {             
          selenium = new DefaultSelenium("localhost",4444, "*firefox C:/Program Files/FF 7.1/firefox.exe", "http://qa02.mydomain.com");
          selenium.start();
          selenium.windowMaximize();

   }

   @AfterClass(alwaysRun=true) 
   public void stopSelenium() {  
   //this.selenium.stop(); 
   } 




   @Test (description="Authentication pop-up")     
          public void Auth_popup() throws Exception
          {


          System.out.print("Unity page\n ");
          try
          {
          selenium.open("/faces/Main");
          Thread.sleep(10000);

          System.out.print("Window \n ");


          String[] dialog;

          dialog = new String[] { "Login_Dialog.exe","Authentication Required","test46#", "test123"};
          System.out.print( dialog);
          Runtime.getRuntime().exec(dialog);


          selenium.select("//select[@id='qryId1::criteriaItems::content']", "Customer Name");
          selenium.type("//input[@id='qryId1:criterionValue::content']", "Search Company");
          selenium.click("//a[@id='qryId1::search_icon']");
          selenium.waitForPageToLoad("3000");

          selenium.click("//a[@id='t1:0:gl1']");


          } catch (SeleniumException ex) {
        System.err.println(ex.getMessage());
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }


   }      

Login.exe code

;~ ------------------------------------------------------------
;~ Login_dialog.au3
;~ To handle the Authentication Dialogbox
;~ Create By: Gaurang Shah
;~ Usage: Login_dialog.au3 "Dialog Title" "User Name" "Password"
;~ ------------------------------------------------------------
AutoItSetOption("WinTitleMatchMode","2")

if $CmdLine[0] < 3 then
msgbox(0,"Error","Supply all the Arguments, Dialog title User Name, Password")
Exit
EndIf

WinWait($CmdLine[1]) ; match the window with substring
$title = WinGetTitle($CmdLine[1]) ; retrives whole window title
ControlSend($title,"","Edit2",$CmdLine[2]);Sets User Name
ControlSend($title,"","Edit3",$CmdLine[3]);Sets Password
ControlClick($title,"","OK");

【问题讨论】:

    标签: selenium authentication popup selenium-rc


    【解决方案1】:

    您可以在基本网址中提供凭据。例如,如果您的基本网址是 http://www.mysite.com/ 然后您可以将其提供为 http://user:pwd@www.mysite.com/

    【讨论】:

    【解决方案2】:

    您可以在 Authorization 标头中传递用户名和密码,这可能会有所帮助:How can I send HTTP Basic Authentication headers in Android?

    【讨论】:

    • 感谢 user861594 的回复。当我运行脚本时,我尝试将基本 url 指定为test64#:test123:qa02.mydomain.com。我收到以下错误。请查看FAILED CONFIGURATION: @BeforeClass setup java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:107) at first.Yahoo_assign.setup(Yahoo_assign.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) SKIPPED: Auth_popup Authentication pop-up
    • 您需要将用户名和密码作为授权标头传递,而不是在 url 中,请尝试查看此示例:java.happycodings.com/Java_Servlets/code36.html
    【解决方案3】:

    尝试在安全弹出窗口出现之前调用您的 autoit 脚本。否则,您将永远无法控制自己。我的意思是在你的主页之前 selenium.open("/faces/Main");

    【讨论】:

    • 感谢您的回复!当我尝试在selenium.open("faces/Main") 之前调用我的脚本时,我没有收到身份验证弹出窗口,并且末尾显示以下错误Timed out after 30000ms 请建议。
    猜你喜欢
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 2014-08-10
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    相关资源
    最近更新 更多