如何在selenium中绕过身份验证

时间:2011-06-16 23:48:55

标签: authentication selenium webdriver

我正在尝试自动化一个安全的应用程序(使用useragent-iphone),当我打开网站时要求进行身份验证。我尝试在URL本身中提供凭据以绕过身份验证,但它会弹出一个对话框进行确认,我无法通过代码处理它。

FirefoxProfile profile = new FirefoxProfile();     
profile.setPreference("general.useragent.override",
    "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1"
    + "(KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3)"); 
WebDriver driver = new FirefoxDriver(profile); 
String site = "http://akamai:ecnt0k3n@ecn13-secure-store.nike.com";
driver.get(site);

对此的任何帮助都非常感谢。

谢谢, Bhavana

2 个答案:

答案 0 :(得分:2)

Mozilla阻止捕鱼尝试。您检查了Network.http.phishy-userpass-length吗?

顺便说一句,根据Selenium's issue 34#8,这应该有效:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.http.phishy-userpass-length", 255);
driver = new FirefoxDriver(profile);
driver.get("http://username:password@www.basicauthprotected.com/");

注意:此问题与BASIC Authentication in Selenium 2 - set up for FirefoxDriver, ChromeDriver and IEdriver几乎相同。

答案 1 :(得分:0)

您可以使用Selenium的新WebDriver将信息输入到该类型的对话框中。但是我还没有这样做。