Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k 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 (62.9k 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!

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s automation testing course!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...