Firefox的Webdriver和代理服务器

Max*_*rai 36 firefox proxy selenium-webdriver foxyproxy

有没有办法设置firefox的代理设置?我在这里找到了有关FoxyProxy的信息,但是当Selenium工作时,插件在窗口中被取消激活.

小智 49

network.proxy.http_port应为整数(不应使用引号),并network.proxy.type应设置为1(ProxyType.MANUAL,手动代理设置)

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);
Run Code Online (Sandbox Code Playgroud)

  • 如果有人告诉我如何在firefox配置文件中设置"user:pass@1.1.1.1:2874",我将不胜感激.我试过`profile.setPreference("network.proxy.http","user:pass@1.1.1.1:2874")`但显然它不起作用. (5认同)
  • 那么代理认证呢? (4认同)
  • @Shane:profile.setPreference( "network.proxy.http", "HTTP://用户:pass@1.1.1.1"),然后profile.setPreference( "network.proxy.http_port",2874)应该工作. (2认同)

Vic*_*tor 22

我刚刚对这个问题感兴趣了几天,我很难找到HTTPS的答案,所以这是我对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);
Run Code Online (Sandbox Code Playgroud)

陷入困境:只输入域而不是http://proxy.domain.example.com,属性名是.ssl和不.https

我现在有更多的乐趣试图让它接受我自己签署的证书......

  • 谢谢,HTTPS仅适用于这些设置 (2认同)

SSH*_*SSH 18

查看文档页面.

调整现有的Firefox配置文件

您需要更改"network.proxy.http"和"network.proxy.http_port"配置文件设置.

FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference("network.proxy.http", "localhost");
profile.addAdditionalPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)

  • 这在2010年可能是正确的,但FirefoxAdrofile上不再存在addAdditionalPreference方法.必须使用setPreference通过FirefoxProfile来执行此操作.另外为了让firefox实际使用代理"network.proxy.type"需要设置为1作为Praveen答案提及或2如果它的PAC作为Saik0显示.Dan Seibert的回答显示,我使用DesiredCapabilities的方式来做这件事. (8认同)

Pra*_*een 9

只是添加到上面给出的解决方案.,

添加"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. 
Run Code Online (Sandbox Code Playgroud)

因此,根据我们的要求,应该按照下面的说明设置"network.proxy.type"值.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
WebDriver driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)


Ste*_*ner 8

WebDriver API已更改.用于设置代理的当前代码段是

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)

  • 那么代理认证呢? (4认同)

Sai*_*pta 5

如果您有自动配置网址 -

        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);
Run Code Online (Sandbox Code Playgroud)


小智 5

这是一个使用的java示例DesiredCapabilities.我用它将硒测试泵入jmeter.(只对HTTP请求感兴趣)

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); 
Run Code Online (Sandbox Code Playgroud)