20

的Chrome 59 removed support for https://user:[email protected] URLs硒鉻60無頭處理基本身份驗證SAML對話框通過HTTPS

我有需要與Chrome Version 60 on Windows in 'headless' mode

ChromeOptions options = new ChromeOptions(); 
options.AddArgument("headless"); 
driver = new ChromeDriver(chrome, options); 

這裏工作一個C#硒測試SAML鑑定所需的對話框我想處理Windows的:基於這裏給出的答案 Basic Auth Dialog

How to handle authentication popup with Selenium WebDriver using Java)我可以看到幾個工作在Firefox處理這一點,但在無頭模式沒有爲Chrome 60。

我試過下面的代碼與訪問憑據的URL訪問測試中的網址(不含憑證)之前,但它似乎有一個bug使用Chrome 60

goTo("http://user:[email protected]"); // Caches auth, but page itself is blocked 
goTo("http://localhost"); // Uses cached auth, page renders fine 
// Continue test as normal 

我可以看到以下在火狐代碼處理認證和對話從來沒有彈出:

FirefoxProfile profile = new FirefoxProfile(); 
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "https://saml.domain.com"); 
profile.EnableNativeEvents = false;` 

我已經試過了第二種方法(using AutoIt),以及適用於Chrome 60,但做ES在無頭模式在Chrome 60 工作。

//Use AutoIt to wait 4 seconds for the authentication required dialog to appear 
au3.Sleep(4000); 
//Use AutoIT to send in the credentials from app.config that are encrypted 
au3.Send(USERNAME + "{TAB}" + PASSWORD + "{ENTER}"); 
//Refresh the page 
driver.Navigate().Refresh(); 

我希望有一個更好的解決方案,現在在2017年,並且有將與Chrome的60 無頭模式下工作,任何指針的方法?

只是要清楚:試圖使用,因爲子資源請求都會被封鎖embedded credentials將不使用Chrome V59 +工作。

+0

可能重複的[Python Selenium Alert - 提示用戶名和密碼不起作用](https://stackoverflow.com/questions/45328654/python-selenium-alert-prompt-username-password-is-not-working) – DebanjanB

+1

你可以檢查這個[** Question/Discussion/Thread **](https://stackoverflow.com/questions/45345882/selenium-other-way-to-basic-authenticate-than-via-url/45352660?noredirect = 1#comment77716943_45352660)。 – DebanjanB

+0

我運行硒測試時,也仍然可以在Chrome瀏覽器中登錄提示。在Windows上,這兩種建議都不適用於Chrome 60無頭模式。 – IanC

回答

0

也許你可以執行使用一個XMLHttpRequest使用方法setRequestHeader,所以你可以指定認證頭先前的連接。執行單個請求後,您將被認證爲所有其他類型的請求。更大的問題可能是XSS,這取決於您可能可以解決的情況。