0 votes
1 view
in Devops and Agile by (25k points)

I want to use selenium with a proxy that is password protected. The proxy is not fixed, but a variable. So this has to be done in the code (just setting up firefox on this particular machine to work with the proxy is less-than-ideal). So far I have the following code:

fp = webdriver.FirefoxProfile()

# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5

fp.set_preference("network.proxy.type", 1)

fp.set_preference("network.proxy.http", PROXY_HOST)

fp.set_preference("network.proxy.http_port", PROXY_PORT)

driver = webdriver.Firefox(firefox_profile=fp)

driver.get("http://whatismyip.com")

At this point, the dialog pops up requesting the proxy user/pass. Is there an easy way to either:

  1. Type in the user/pass in the dialog box.
  2. Provide the user/pass at an earlier stage.

 

1 Answer

0 votes
by (63.3k points)
edited by

I will be providing here python code which helps you enter HTTP proxy password for firefox, hope you can translate it to python:

from selenium import webdriver

 

PROXY_HOST = "IP_address"

PROXY_PORT = "your_proxy_port"

USERNAME = "your_user_name" 

PASSWORD = "YOUR_PASSWORD"

 

profile = webdriver.FirefoxProfile()

profile.set_preference("network.proxy.type", 1)

profile.set_preference("network.proxy.http", PROXY_HOST)

profile.set_preference("network.proxy.http_port", PROXY_PORT)

profile.set_preference("network.proxy.socks_username", USERNAME)

profile.set_preference("network.proxy.socks_password", PASSWORD)

 

profile.update_preferences()

 

# executable_path  = define the path if u don't already have in the PATH system variable. 

browser = webdriver.Firefox(firefox_profile=profile)

browser.get('https://www.intellipaat.com/')

browser.maximize_window()

I hope this helps!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...