2017-05-24 86 views
0

我想打开一个内部网网站与硒重定向到另一个链接登录,并返回到有效登录的原始URL。例如 - 当我启动webdriver并导航到原始网站的URL https://DemoOriginalWebsite.Com浏览器被重定向到https://Validateyourselfbeforeaccessing.com:9030并显示下面的弹出窗口输入用户名和密码。如何填写身份验证与铬硒铬弹出#

Popup window

我试图如下传递凭证,但没有奏效。

尝试1:http://username:[email protected]

尝试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:[email protected]"); 

任何建议,请。

回答

0

您将不得不使用AutoIT。安装AutoIT,将脚本写入AutoIT并将其导出为.exe文件。这个.exe你将不得不打电话在你的硒

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. 
+1

谢谢。让我尝试。 –

+0

酷兄弟。 AutoIT就像你一样令人惊叹。我已将网络驱动程序更改为Internet Explorer,因为它可以让我弹出适当的窗口。将添加我的工作代码,以供读者参考。谢谢。 –

+1

也有一个内容丰富的视频。 https://youtu.be/civzNtKTCD0 –

1

这是我怎么想出来的。

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