How to set proxy in Firefox Webdriver Permanently

Viewed 402

Since I cannot set a proxy from Geckodriver directly, I will change it manually by using

from selenium import webdriver


myProxy = "xxxxxxxxx:yyyy"
ip, port = myProxy.split(":")


profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy_type',5)
profile.set_preference('network.proxy.http','xxxxxxxxx')
profile.set_preference('network.proxy.http_port',yyyy)
profile.update_preferences()

driver=webdriver.Firefox(firefox_profile=profile)
driver.get('http://www.google.co.th')
time.sleep(3)
driver.close()

I am trying to execute, the firefox has changes into proxy mode

However, when I execute script via Robot Framework, which it also execute via Geckodriver, it doesn't change into proxy.

I need to know the way to permanently change proxy in Geckodriver

1 Answers

With SeleniumLibrary's Open Browser keyword you could set any preferences like you would do in your Python script.

For example the following test would open a browser every time with these options:

  1. Proxy HTTP port set to 777.
  2. Proxy type set to "5".
  3. Proxy HTTP "xxxxxxxxx".

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Test
    Open Browser    http://example.com    Firefox   ff_profile_dir=set_preference("network.proxy_type", "5");set_preference("network.proxy.http", "xxxxxxxxx");set_preference("network.proxy.http_port", 777)   # Defining profile using FirefoxProfile mehtods.
    Sleep    1 min    reason=Verify proxy settings manually in the opened browser.

Values checked on the Firefox's about:config page during sleep:

enter image description here

Related