我正在尝试使用以下代码处理身份验证弹出窗口:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.http.phishy-userpass-length", 255);
profile.setPreference("network.automatic-ntlm-auth.trusted-uris", "x.x.x.x");
driver = new FirefoxDriver(profile);
baseUrl="http://" + login + ":" + password + "@" + url;
driver.get(baseUrl + "/");
Run Code Online (Sandbox Code Playgroud)
当我执行测试时,页面显示身份验证弹出窗口,并且仍然加载直到我单击取消按钮.那一刻,我可以访问下一页,这意味着身份验证成功但仍然始终显示身份验证弹出窗口
我无法使用无头模式在Google Chrome中使用我当前安装的扩展程序.有没有办法启用它们?
检查扩展是否有效的简单方法是添加,例如," Comic Sans Everything "扩展.
谷歌看起来像这样:
但是,如果我使用无头模式(google-chrome --headless --disable-gpu --screenshot https://www.google.com)拍摄页面的屏幕截图,结果是:
google-chrome google-chrome-extension google-chrome-headless
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 …Run Code Online (Sandbox Code Playgroud) c# basic-authentication selenium-chromedriver selenium-webdriver
我想使用selenium和受密码保护的代理.代理不是固定的,而是一个变量.所以这必须在代码中完成(只需在这台特定的机器上设置firefox以使用代理就不太理想了).到目前为止,我有以下代码:
fp = webdriver.FirefoxProfile()
# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", PROXY_PORT)
driver = webdriver.Firefox(firefox_profile=fp)
driver.get("http://whatismyip.com")
Run Code Online (Sandbox Code Playgroud)
此时,弹出对话框,请求代理用户/通过.
是否有一种简单的方法: