2017-05-24 93 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