Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I'm using the Python bindings for Selenium2 with the Chrome webdriver. I need to access a site that is protected with basic HTTP authentication.

from selenium import webdriver

driver = webdriver.Chrome() 
driver.get('http://username:password@example.com')

I would expect this to work, but it seems that Chrome ignores the username and password given as part of the URL. Chrome will pop the authentication dialog and the script will hang until I manually type in the credentials. Chrome will forget this username and password, so I have to type it in every time I run the script.

share|improve this question
2  
This kinds of question comes up a lot here. Have you tried searching the site for "selenium basic authentication" (sqa.stackexchange.com/…)? –  user246 May 30 '12 at 14:25
    
It's been a long time since I posted this, but the above code now works with the latest selenium bindings and the latest Chrome webdriver. (selenium-python.readthedocs.org/en/latest/installation.html & code.google.com/p/selenium/wiki/ChromeDriver) –  jrdmcgr Mar 19 '13 at 20:32
add comment

2 Answers

If you are running on Windows you can create a little executable that fills the popup and presses OK using AutoHotkey, and run it after driver.get()

Maybe it's not the cleanest solution, but it works.

share|improve this answer
    
This does not cover well where we have re-directs, delayed redirects and links that all result in pages that need http authentication, and including SSL connections. Fun and games with getting the timing right using Autoit (similar solution as presented here - AutoHotkey). –  user4515 Dec 11 '12 at 12:08
add comment

Does this help ? (ops, after the trouble, I realized your issue is with Chrome) but this is working fine on Firefox 9.0.1 on Windows 7

    String configFile = "/apps/configs/logins.cfg";

    // server, port, userid, password defaults
    String userid   = "willey@customer.com";
    String password = "willeyCoy0tt3";
    String server     = "desert.acme.com";
    String securePort = "447";

    // load the properties file - this might throw an exception
    //    if it cannot find or cannot open the file 
    Properties prop = new Properties();
    prop.load(new FileInputStream( configFile ));

    //get the values
    userid   = prop.getProperty( "user" );
    password = prop.getProperty( "password" );

    baseUrl = "https://" + userid + ":" + password + "@" + server + ":" + securePort + "/services/login.html";

    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);

    // after that, just use to load the other pages, for example
    driver.get(baseUrl + "/services/listOrders.html");
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.