Ian*_*anC 32 c# basic-authentication selenium-chromedriver selenium-webdriver
Chrome 59 删除了对https:// user:password@example.com网址的支持.
我有一个C#selenium测试需要在Windows上以" 无头 "模式使用Chrome版本60
ChromeOptions options = new ChromeOptions();
options.AddArgument("headless");
driver = new ChromeDriver(chrome, options);
Run Code Online (Sandbox Code Playgroud)
这是我试图在Windows上处理的SAML身份验证所需对话框:

基于这里给出的答案:如何使用Java处理Selenium WebDriver的身份验证弹出窗口我可以看到在FireFox中处理此问题的几种解决方法,但在无头模式下Chrome 60没有.
在访问测试中的URL之前,我尝试使用以下代码访问带有凭据的URL(没有凭据)但是看起来Chrome 60 存在错误.
goTo("http://user:password@localhost"); // Caches auth, but page itself is blocked
goTo("http://localhost"); // Uses cached auth, page renders fine
// Continue test as normal
Run Code Online (Sandbox Code Playgroud)
我可以看到Firefox中的以下代码处理身份验证,对话框永远不会弹出:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "https://saml.domain.com");
profile.EnableNativeEvents = false;`
Run Code Online (Sandbox Code Playgroud)
我试过(第二种方法使用的AutoIt),以及适用于Chrome 60,但确实不是在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();
Run Code Online (Sandbox Code Playgroud)
我希望2017年有一个更好的解决方案,并且有一种方法可以在无头模式下使用Chrome 60 ,任何指针?
需要明确的是:尝试使用嵌入式凭据将无法使用chrome v59 +,因为子资源请求将被阻止.
也许您可以使用 setRequestHeader 方法使用 XMLHttpRequest 执行先前的连接,以便您可以指定身份验证标头。执行单个请求后,您将通过所有其他类型请求的身份验证。更大的问题可能是 XSS,根据您的情况,您也许可以解决它。
| 归档时间: |
|
| 查看次数: |
2835 次 |
| 最近记录: |