четверг, 15 ноября 2012 г.

Selenium Webdriver with htpasswd (Authentication Required)


How can I use Selenium Webdriver to login to the site with htpasswd - Authentication Required (modal dialog with HTTP basic authentication)



I know only one way to login to the site with htpasswd protection - it is use username and password in the URL (something like this: http://username:password@example.com/test ):

public static void main(String[] args) {

 // Create a new instance of the Firefox driver
 WebDriver driver = new FirefoxDriver();

  // And now use this to visit website with htpasswd
 driver.get("http://username:password@example.com");

}


By the way, this won't work in Internet Explorer because Microsoft has disabled username/password in URLs - ref.
To fix that you can set an "iexplore.exe" DWORD to 0 in HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE.

1 комментарий: