Nava
Nava

Reputation: 6556

How to pass over the HttpAuthentication into selenium webdriver

In my python project, the login process is handled by the HttpBasicAuth handler. After getting the response I should load the main page via selenium.

How it is supposed to be done?

It has the baseurl. When the base url is loaded by python-selenium, the pop-up box asks for the username and password for authentication. Then it enters into main page.

Here are the two steps:

The reason I am using the HttpBasicAuth handler is that when I open my url it opens a popup window for login. Since, we didn't know the control of the popup-modal dialog window to be handled by Selenium, we switched to HttpAuthentication.

(This is the part I need suggestions for.)

In this intermediate part I use the response from HttpBasicAuth handler to authenticate so that Selenium can continue with the other steps in the test.

How can I make the site authenticated in Selenium? Do I have to create a cookie for Selenium webdriver by using HttpBasicAuthentication Response so as to skip the login box?

Upvotes: 0

Views: 5664

Answers (1)

Uku Loskit
Uku Loskit

Reputation: 42040

This is a problem that could easily be solved by adding header to your HTTP response, unfortunately Selenium2 does not support this feature.

You could try using it like this by embeddeing the username and password in the URL:

browser = webdriver.Firefox() # Get local session of firefox
browser.get("http://myusername:[email protected]") # Load page

Note this does not work for IE (due to security issues), but you can make it work by modifying the registry a bit.

As per your comment, I do not really understand your question. If you do the first request as I specified, the browser will automatically store a special Authorization: header with the password and username concatenated and base64-encoded. All the other requests will be now authenticated until you close the browser.

This method has little to do with Selenium 1 or Selenium 2, but what the specific browser supports. IE is the only browser that I know that restricts this.

Upvotes: 5

Related Questions