Suppose you need to use proxy servers for some of your scenarios (unique visitors). Since each test case may use many proxies, changing the global system proxy settings is a rather bad idea. Fortunately HTTP proxies may be configured in a web browser. If you inspect the Firefox about:config panel, you will notice many properties that configure how your browser really acts. We'll be interested in the network.proxy.* settings.
from selenium import webdriver from selenium.common.exceptions import TimeoutException try: proxy = "192.168.1.3" port = 8080 fp = webdriver.FirefoxProfile() fp.set_preference('network.proxy.ssl_port', int(port)) fp.set_preference('network.proxy.ssl', proxy) fp.set_preference('network.proxy.http_port', int(port)) fp.set_preference('network.proxy.http', proxy) fp.set_preference('network.proxy.type', 1) browser = webdriver.Firefox(firefox_profile=fp) browser.set_page_load_timeout(15) browser.get('http://192.168.1.1/test') print browser.find_element_by_id('my_div').text except TimeoutException as te: print "timeout" except Exception as ex: print ex.message finally: browser.quit()
First we need to configure our profile by setting the HTTP, and HTTPS proxies. Secondly we have to tell Firefox to start using them: network.proxy.type -> 1. Finally we create an instance of Firefox with our proxy settings and execute out test routine.
Have fun!
~KR