【问题标题】:How to fill Authentication Required popup in chrome with Selenium C#如何使用 Selenium C# 在 chrome 中填充 Authentication Required 弹出窗口
【发布时间】:2017-05-24 16:10:20
【问题描述】:

我正在尝试使用 Selenium 打开一个 Intranet 网站,该网站重定向到另一个登录链接,并在有效登录时返回原始 URL。例如 - 当我启动 webdriver 并导航到原始站点 URL https://DemoOriginalWebsite.Com 时,浏览器会被重定向到 https://Validateyourselfbeforeaccessing.com:9030 并在弹出窗口下方显示以输入用户 ID 和密码。

我尝试如下传递凭据,但没有成功。

尝试 1: http://username:pswd@DemoOriginalWebsite.Com

尝试 2: https://username:pswdValidateyourselfbeforeaccessing.com:9030

无法直接访问认证URL。

我的实际代码:

IWebDriver chromeDriver;
ChromeOptions options = new ChromeOptions();
options.AddArgument("disable-infobars");
options.AddUserProfilePreference("credentials_enable_service", false);        
options.AddUserProfilePreference("profile.password_manager_enabled", false);
chromeDriver = new ChromeDriver(options);
chromeDriver.Manage().Window.Maximize();     chromeDriver.Navigate().GoToUrl(@"http://username:pswd@DemoOriginalWebsite.Com");

请有任何建议。

【问题讨论】:

    标签: c# selenium selenium-webdriver chrome-web-driver


    【解决方案1】:

    您必须使用 AutoIT。安装 AutoIT,在 AutoIT 中编写脚本并将其导出为 .exe 文件。这个 .exe 你必须在你的 selenium 中调用

    WinWait("Untitled - Google Chrome", "" , 10)) //This will wait for 10 seconds for window with the specified title
    WinActivate("Untitled - Google Chrome"); // This will send the focus of the cursor to the window with the specified title
    Send("username");
    
    //1st argument : moves the cursor's focus from Username textbox to Password text box.  
    //2nd argument : false,  over here tell that it is not a text but raw key
    Send("{TAB}", false); 
    Send("password");
    Send("{Enter}", false);// this will mimic the action of pressing enter button.
    

    【讨论】:

    • 谢谢。让我试试。
    • 酷哥。 AutoIT 和您一样令人惊叹。我已将网络驱动程序更改为 Internet Explorer,因为它为我提供了正确的窗口弹出窗口。将添加我的工作代码以供读者参考。谢谢。
    • 很高兴能为您提供帮助。谢谢
    【解决方案2】:

    这就是我的想法。

    1 - 将 AutoIt NuGet 包添加到项目中。

    2 - 如下使用:

    IWebDriver driverIE = new InternetExplorerDriver();
    driverIE.Manage().Window.Maximize();
    driverIE.Navigate().GoToUrl(@"https://DemoOriginalWebsite.Com");
    AutoItX.ControlFocus("Windows Security", "", "Edit1");
    AutoItX.ControlSetText("Windows Security", "", "Edit1","userid");
    AutoItX.ControlFocus("Windows Security", "", "Edit2");
    AutoItX.ControlSetText("Windows Security", "", "Edit2", "password");
    AutoItX.ControlClick("Windows Security", "", "Button2");
    //Do your work.
    driverIE.Dispose();
    

    我遵循的教程。 Tutorial 1Tutorial 2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-10
      • 2023-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      相关资源
      最近更新 更多