【问题标题】:Unable to create profile for firefox using Selenium无法使用 Selenium 为 Firefox 创建配置文件
【发布时间】:2016-08-31 11:52:55
【问题描述】:

我正在为 Java 使用 selenium 3.0.0-beta2。我无法设置代理。我已经尝试了很多东西,但没有任何效果。我尝试了以下,

 `String PROXY = "localhost:8080";
  DesiredCapabilities.
  Proxy proxy = new Proxy();
  proxy.setHttpProxy(PROXY).setFtpProxy(PROXY).setSslProxy(PROXY)
    .setSocksProxy(PROXY);
  DesiredCapabilities cap = new DesiredCapabilities();
  cap.setCapability(CapabilityType.PROXY, proxy);
  driver = new FirefoxDriver(cap);`

我也试过这个:

`FirefoxProfile profile = new FirefoxProfile();
 profile.setPreference("network.proxy.type", 1);
 profile.setPreference("network.proxy.http", "someproxy");
 profile.setPreference("network.proxy.http_port", 3128);
 WebDriver driver = new FirefoxDriver(profile);`

我在火狐上使用 geckodriver。我将它定义为这样的系统属性
System.setProperty("webdriver.gecko.driver", ".\\lib\\geckodriver.exe");

我还发现here 尚不支持代理功能。有没有办法设置代理?

【问题讨论】:

    标签: java selenium firefox proxy


    【解决方案1】:

    你可以试试这个

    `ProfilesIni allProfiles = new ProfilesIni(); 
    FirefoxProfile profile = allProfiles.getProfile("default"); 
    profile.setPreference("network.proxy.type", 1); 
    profile.setPreference("network.proxy.http", "someproxy"); 
    profile.setPreference("network.proxy.http_port", 3128);
    capabilities.setCapability("firefox_profile", profile);' 
    

    【讨论】:

      【解决方案2】:

      好的,我已将 Selenium 降级到版本 2 并设置代理,setPreference 方法有效。

      【讨论】:

        猜你喜欢
        • 2016-06-25
        • 2013-10-16
        • 2016-09-11
        • 1970-01-01
        • 1970-01-01
        • 2015-10-01
        • 2020-07-21
        • 2016-12-25
        • 2017-10-14
        相关资源
        最近更新 更多