How to set proxy AUTHENTICATION username:password using Python/Selenium

Viewed 5524

I am using:

  • Selenium 4
  • python 3.7
  • Firefox webdriver

I need to verify the username and password for my current project. I've been working day and night for days and I can't solve this problem. I've found a few extension on the internet, but it's from '13 year and I guess that's why it doesn't work. You can also see other methods I've tried below.

But doesn't work, because Proxy Authentication is not working anymore due to the Selenium bug..

alert_popup = browser.switch_to_alert()
    alert_popup.send_keys(
        "{username}{tab}{password}{tab}".format(
            username=proxy_username, tab=Keys.TAB, password=proxy_password
    )
)
alert_popup.accept()

I wanted to create a profile and save the proxy information manually and start selenium with that profile. However, firefox does not allow user name and password to be entered manually.

1 Answers

To use proxies with auth in python selenium you can use seleniumwire.

Fistly, install it with pip install selenium-wire

Then import webdriver from seleniumwire instead selenium

Check the original Answer here

    from seleniumwire import webdriver
options = {
    'proxy': {
        'http': 'http://username:password@host:port', 
        'https': 'https://username:password@host:port',
        'no_proxy': 'localhost,127.0.0.1' # excludes
    }
}
browser = webdriver.Chrome(path_to_driver, seleniumwire_options=options)
Related