Opening a password protected page in Python and Selenium WebDriver
Question: I am trying to open this local IP in my web browser.

    
    
       from selenium import webdriver
        driver = webdriver.Firefox()
        url = 'http://165.269.261.210/source/'
        page = urllib.urlopen(url)
    

when I run the above code it asks for username and password on Python shell.

    
    
    Enter username for coffee at 165.269.261.210: agrawal
    
    Warning (from warnings module):
      File "C:\Python27\Lib\getpass.py", line 92
        return fallback_getpass(prompt, stream)
    GetPassWarning: Can not control echo on the terminal.
    Warning: Password input may be echoed.
    Enter password for agrawal.a in coffee at 165.269.261.210: bravokid
    

after I provide username and password nothing opens in Firefox ? and also how
can I provide username and password in the code itself ? Is there any better
way to do it?

Update: When I directly put the link in the browser a pop-up opens asking for
username and password. Only after I provide the username & password page opens
otherwise throws 401 error


Answer: What you are doing here:

    
    
    from selenium import webdriver
    driver = webdriver.Firefox()
    url = 'http://165.269.261.210/source/'
    
    # This is no way connected to Selenium, but fetches URL using Python urllib library
    # page = urllib.urlopen(url)
    driver.get('http://username:password@165.269.261.210/source/')
    

Instead, use `driver.get()` method as [explained in the Selenium WebDriver
tutorial](http://selenium-python.readthedocs.org/en/latest/getting-
started.html).

[Further, you need to pass username and password in the URL for HTTP Basic
Auth](http://stackoverflow.com/a/9262587/315168).

