firefox的Webdriver和代理服务器

firefox的Webdriver和代理服务器,firefox,proxy,selenium-webdriver,foxyproxy,Firefox,Proxy,Selenium Webdriver,Foxyproxy,有没有办法设置firefox的代理设置?我在这里找到了有关FoxyProxy的信息,但当Selenium工作时,窗口中的插件未激活。首选项->高级->网络->连接(配置Firefox连接到Internet的方式)查看 调整现有Firefox配置文件 您需要更改“network.proxy.http”和“network.proxy.http_port”配置文件设置 FirefoxProfile profile = new FirefoxProfile(); profile.addAdditiona

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

首选项->高级->网络->连接(配置Firefox连接到Internet的方式)

查看

调整现有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);

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

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

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


还有另一个解决方案,我在寻找,因为a的代码有这样的问题(它在firefox中设置了系统代理):

我更喜欢这个解决方案,它强制firefox中的代理手动设置。 为此,请使用org.openqa.selenium.Proxy对象设置Firefox:

FirefoxProfile profile = new FirefoxProfile();
localhostProxy.setProxyType(Proxy.ProxyType.MANUAL);
localhostProxy.setHttpProxy("localhost:8080");
profile.setProxyPreferences(localhostProxy);
driver = new FirefoxDriver(profile);
如果它能帮助…基于PAC的URL

 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);
我希望这能有所帮助

FirefoxProfile profile = new FirefoxProfile();
String PROXY = "xx.xx.xx.xx:xx";
OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
proxy.HttpProxy=PROXY;
proxy.FtpProxy=PROXY;
proxy.SslProxy=PROXY;
profile.SetProxyPreferences(proxy);
FirefoxDriver driver = new FirefoxDriver(profile);

这是针对C#

的,我在这几天里对这个问题很感兴趣,我很难找到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);
这里的问题:只输入域,而不是
http://proxy.domain.example.com
,属性名称是
.ssl
,而不是
.https


我现在更喜欢尝试让它接受我的自签名证书…

以防你有一个自动配置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);

下面是一个使用
DesiredCapabilities
的java示例。我用它把硒测试注入jmeter。(只对HTTP请求感兴趣)

Firefox代理: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);

除了上述给定的解决方案之外

添加“network.proxy.type”的可能性列表(整数值)

因此,根据我们的要求,“network.proxy.type”值应设置如下所述

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
WebDriver driver = new FirefoxDriver(profile);
根据

从selenium导入webdriver
PROXY=“”
webdriver.DesiredCapabilities.FIREFOX['proxy']={
“httpProxy”:代理,
“ftpProxy”:代理,
“sslProxy”:代理,
“proxyType”:“手动”,
}
使用webdriver.Firefox()作为驱动程序:
#打开URL
驱动程序。获取(“https://selenium.dev")

我知道这一点。当Selenium为工作运行firefox窗口时,带有代理的连接选项卡为空。如果有人告诉我如何设置“用户:pass@1.1.1.1:2874“在firefox配置文件中,我们将不胜感激。我尝试了
profile.setPreference(“network.proxy.http”,“用户:pass@1.1.1.1:2874“
但显然它不起作用。代理身份验证呢?@Shane:profile.setPreference(“network.proxy.http”,”),然后profile.setPreference(“network.proxy.http_port”,2874)应该可以。@Arya:事实上,我发现
webdriver
对于我当时试图做的大量工作来说太笨拙了,所以我转向
请求(一个python库)对于纯
HTTP/HTTPS
请求来完成我的工作。代理身份验证如何?如何在此代理中进行身份验证?我正在以
http://code:Blue%4019@proxypath.pac
。但我无法加载任何页面。这在2010年可能是正确的,但FirefoxProfile setPreferen上不再存在addAdditionalPreference方法ce必须通过FirefoxProfile来实现这一点。此外,为了让firefox真正使用代理,“network.proxy.type”需要在Praveen回答中提到时设置为1,如果是PAC,则设置为2,如Saik0所示。我使用DesiredCapabilities的方法来实现这一点,如Dan Seibert的回答所示。是否有自签名证书的运气?:)
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); 
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 - Direct connection (or) no proxy. 

1 - Manual proxy configuration

2 - Proxy auto-configuration (PAC).

4 - Auto-detect proxy settings.

5 - Use system proxy settings. 
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
WebDriver driver = new FirefoxDriver(profile);
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")