Webdriver and proxy server for firefox

后端 未结 13 2285
清歌不尽
清歌不尽 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-11-30 23:57

    I just had fun with this issue for a couple of days and it was hard for me to find an answer for HTTPS, so here's my take, for Java:

        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", "proxy.domain.example.com");
        profile.setPreference("network.proxy.http_port", 8080);
        profile.setPreference("network.proxy.ssl", "proxy.domain.example.com");
        profile.setPreference("network.proxy.ssl_port", 8080);
        driver = new FirefoxDriver(profile);
    

    Gotchas here: enter just the domain and not http://proxy.domain.example.com, the property name is .ssl and not .https

    I'm now having even more fun trying to get it to accept my self signed certificates...

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

    Just to add to the above given solutions.,

    Adding the list of possibilities (integer values) for the "network.proxy.type".

    0 - Direct connection (or) no proxy. 
    
    1 - Manual proxy configuration
    
    2 - Proxy auto-configuration (PAC).
    
    4 - Auto-detect proxy settings.
    
    5 - Use system proxy settings. 
    

    So, Based on our requirement, the "network.proxy.type" value should be set as mentioned below.

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

    Here's a java example using DesiredCapabilities. I used it for pumping selenium tests into jmeter. (was only interested in HTTP requests)

    import org.openqa.selenium.Proxy;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    String myProxy = "localhost:7777";  //example: proxy host=localhost port=7777
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY,
                               new Proxy().setHttpProxy(myProxy));
    WebDriver webDriver = new FirefoxDriver(capabilities); 
    
    0 讨论(0)
  • 2020-12-01 00:06

    According to the latest documentation

    from selenium import webdriver
    
    PROXY = "<HOST:PORT>"
    webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
        "httpProxy": PROXY,
        "ftpProxy": PROXY,
        "sslProxy": PROXY,
        "proxyType": "MANUAL",
    
    }
    
    with webdriver.Firefox() as driver:
        # Open URL
        driver.get("https://selenium.dev")
    
    0 讨论(0)
  • 2020-12-01 00:16

    For PAC based urls

     Proxy proxy = new Proxy();
     proxy.setProxyType(Proxy.ProxyType.PAC);
     proxy.setProxyAutoconfigUrl("http://some-server/staging.pac");
     DesiredCapabilities capabilities = new DesiredCapabilities();
     capabilities.setCapability(CapabilityType.PROXY, proxy);
     return new FirefoxDriver(capabilities);
    

    I hope this could help.

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

    Firefox Proxy: JAVA

    String PROXY = "localhost:8080";
    
    org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
    
    proxy.setHttpProxy(PROXY)setFtpProxy(PROXY).setSslProxy(PROXY);
    
    DesiredCapabilities cap = new DesiredCapabilities();
    
    cap.setCapability(CapabilityType.PROXY, proxy); 
    
    WebDriver driver = new FirefoxDriver(cap);
    
    0 讨论(0)
提交回复
热议问题