Login to Chrome Authentication window using AutoIT

前提是你 提交于 2019-12-09 01:50:31

问题


I tried login to firefox authentication window by following code :

WinWaitActive("Authentication Required","","120")
If WinExists("Authentication Required") Then
Send("username{TAB}")
Send("password{Enter}")
EndIf

But the same dint worked for chrome even though it has the same title as firefox.

Any idea?


回答1:


@Milos @Samoth thanks for spending to solve my query.

Using Autoit windows info tool, i could not identify the windows tile in chrome thats not a case in FF or IE. Instead of that "Autentication Required" identified as visible text.

So modifying the code to

WinWaitActive("","Authentication Required","120")
If WinExists("","Authentication Required") Then
Send("username{TAB}")
Send("password{Enter}")
EndIf

did the trick for Chrome browser.




回答2:


If somebody is interested in Selenium for Chrome using Visual Studio and NUnit Framework, you can follow these steps:

  1. Install AutoItX.Dotnet NuGet package for your testing project

  2. Write the following code:

        IWebDriver _driver = new ChromeDriver();
        _driver.Navigate().GoToUrl(@"your_url");
    
        AutoItX.WinActivate("", "Authentication required");
        AutoItX.Send(@"domain_user_name{TAB}password{ENTER}");
    

and you are logged in your web application.




回答3:


A lot of credit for this goes to @CristiG for this.

  1. You will need the AutoItX.Dotnet NuGet package
  2. Use this code to login, just ignore the commented out lines unless you want to see if you can get it to work without the Sleep() for robustness.
     new Thread(() =>
            {
                Thread.Sleep(500);
                // AutoItX.WinWait("", "Authentication required");//fails
                AutoItX.WinActivate("", "Authentication required");
                // AutoItX.WinWaitActive("", "Authentication required");//fails
                AutoItX.Send(@"username{TAB}pass{ENTER}");
            }).Start();

            driver.Url = "http://yourpage.com";

Cristi's method didn't work for me, because the call to GoToUrl() blocks when the login dialog box pops up. But that can be fixed simply by starting a thread to do the login before calling GoToUrl(). It would seem you could use either WinWait() or WinWaitActive() to eliminate the need for the Thread.Sleep(), but I couldn't get either to work, so I was left with the ugly Thread.Sleep(), but this approach works for me.



来源:https://stackoverflow.com/questions/20568387/login-to-chrome-authentication-window-using-autoit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!