http://username:password@xyz.com
经过几个小时的阅读,我终于找到了解决方案,它非常有效,我希望这也能帮助其他人。-享受吧!
首先-按照以下步骤进行:
1) Open the FireFox browser
2) Type the following `about:config`
3) Look for `network.http.phishy-userpass-length` if you don't find then create a new Integer key
Create a new Integer key (right-click->New->Integer): `network.http.phishy-userpass-length` with value `255`
第二步:您需要使用以下内容创建Firefox驱动程序:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.http.phishy-userpass-length", 255);
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "YOUR HOST ADDRESS HERE");
_driver = new FirefoxDriver(profile);
如果您有任何问题,请告诉我。
network.negotiate-auth.delegation-uris: MyIISServer.domain.com
network.automatic-ntlm-auth.trusted-uris: MyIISServer.domain.com
network.automatic-ntlm-auth.allow-proxies: True
network.negotiate-auth.allow-proxies: True
在WebDriver启动的Firefox配置文件中设置。一旦您创建并保存了配置文件(当没有其他实例运行时运行“Firefox -P”来选择配置文件),您可以在代码中执行以下操作:
File profileDir = new File("C:/wherever/SeleniumFirefoxProfile");
FirefoxProfile profile = new FirefoxProfile(profileDir);
profile.setEnableNativeEvents(true);
driver = new FirefoxDriver(profile);
FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");
File pluginAutoAuth = new File("D:\\autoauth-2.1-fx+fn.xpi");
firefoxProfile.addExtension(pluginAutoAuth);
driver = new FirefoxDriver(firefoxProfile);
我使用了 "autoauth-2.1-fx+fn.xpi"。
我曾经几次处理过这些问题,我的方法是使用 Selenium 之外的脚本。你正在使用 Windows 吗?
基本上做法如下:
1) 在加载页面、单击 URL 等触发该对话框出现之前:
-- Launch an asynchronous script to handle the login
2) 然后加载页面,点击链接等
-- Selenium will block until your asynch script completes
-- Sleep for a few seconds
-- Activate the dialog
-- Send the username
-- Send a TAB
-- Send the password
-- Send a TAB
-- Send the Enter Key
http://username:password@the-site.com
- 但仍然不起作用... 仍然要求输入用户名/密码。 - Nick Kahn