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:[email protected]')

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

2 Answers 2

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   = "[email protected]";
    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.

1
  • 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, 2012 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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