Webdriver and proxy server for firefox

后端 未结 13 2286
清歌不尽
清歌不尽 2020-11-30 23:49

are there any ways to set firefox\'s proxy settings? I found here information about FoxyProxy but when Selenium works, plugins are unactivated in window.

相关标签:
13条回答
  • 2020-12-01 00:17

    Value for network.proxy.http_port should be integer (no quotes should be used) and network.proxy.type should be set as 1 (ProxyType.MANUAL, Manual proxy settings)

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", "localhost");
    profile.setPreference("network.proxy.http_port", 3128);
    WebDriver driver = new FirefoxDriver(profile);
    
    0 讨论(0)
  • 2020-12-01 00:17

    Preferences -> Advanced -> Network -> Connection (Configure how Firefox connects to the Internet)

    0 讨论(0)
  • 2020-12-01 00:18

    There is another solution, i looked for because a had problems with code like this (it s set the system proxy in firefox):

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.http", "localhost");
    profile.setPreference("network.proxy.http_port", "8080");
    driver = new FirefoxDriver(profile);
    

    I prefer this solution, it force the proxy manual setting in firefox. To do that, use the org.openqa.selenium.Proxy object to setup Firefox :

    FirefoxProfile profile = new FirefoxProfile();
    localhostProxy.setProxyType(Proxy.ProxyType.MANUAL);
    localhostProxy.setHttpProxy("localhost:8080");
    profile.setProxyPreferences(localhostProxy);
    driver = new FirefoxDriver(profile);
    

    if it could help...

    0 讨论(0)
  • 2020-12-01 00:19

    The WebDriver API has been changed. The current snippet for setting the proxy is

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.http", "localhost");
    profile.setPreference("network.proxy.http_port", "3128");
    WebDriver driver = new FirefoxDriver(profile);
    
    0 讨论(0)
  • 2020-12-01 00:19

    In case if you have an autoconfig URL -

            FirefoxProfile firefoxProfile = new FirefoxProfile();
            firefoxProfile.setPreference("network.proxy.type", 2);
            firefoxProfile.setPreference("network.proxy.autoconfig_url", "http://www.etc.com/wpad.dat");
            firefoxProfile.setPreference("network.proxy.no_proxies_on", "localhost");
            WebDriver driver = new FirefoxDriver(firefoxProfile);
    
    0 讨论(0)
  • 2020-12-01 00:20

    Look at the documentation page.

    Tweaking an existing Firefox profile

    You need to change "network.proxy.http" & "network.proxy.http_port" profile settings.

    FirefoxProfile profile = new FirefoxProfile();
    profile.addAdditionalPreference("network.proxy.http", "localhost");
    profile.addAdditionalPreference("network.proxy.http_port", "3128");
    WebDriver driver = new FirefoxDriver(profile);
    
    0 讨论(0)
提交回复
热议问题