4

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.

2

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");
1

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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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