Firefox的Webdriver和代理服务器

时间:2010-05-22 11:58:45

标签: firefox proxy selenium-webdriver foxyproxy

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

13 个答案:

答案 0 :(得分:47)

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);

答案 1 :(得分:21)

我对这个问题感兴趣了几天,我很难找到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

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

答案 2 :(得分:18)

请看the documentation page

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

答案 3 :(得分: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. 

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

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

答案 4 :(得分: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);

答案 5 :(得分: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);

答案 6 :(得分:5)

这是使用DesiredCapabilities的java示例。我用它将硒测试泵入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); 

答案 7 :(得分:4)

基于PAC的网址

 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);

我希望这可以提供帮助。

答案 8 :(得分:1)

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);

答案 9 :(得分:1)

根据latest documentation

#include<iostream>

using namespace std;

class node{
public:
    int data;
    node *next;
}*head,*newnode,*temp;

node* getnode();
node* create(int);
void display(node*);

int main()
{
    int n;
    head=getnode();
    cout<<"Enter the no of nodes: ";
    cin>>n;
    head=create(n);
    display(head);
    return 0;
}

node *getnode()
{
    head=new node();
    head->next=nullptr;
    return(head);
}

node *create(int n)
{
    head=getnode();
    cout<<"Enter the value of node 1: ";
    cin>>head->data;
    temp=getnode();
    temp=head;
    for(int i=1;i<n;i++)
    {
        newnode=getnode();
        cout<<"Enter the value of node "<<i+1<<": ";
        cin>>newnode->data;
        newnode->next=nullptr;
        temp->next=newnode;
        temp=newnode;
    }
    return(head);
}

void display(node *head)
{
    while(head!=nullptr)
    {
        cout<<"->"<<head->data;
        head=head->next;
    }
}

答案 10 :(得分:0)

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

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

我更喜欢这个解决方案,它强制在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);

如果有帮助......

答案 11 :(得分:0)

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#

答案 12 :(得分:-4)

偏好设置 - &gt;高级 - &gt;网络 - &gt;连接(配置Firefox连接到Internet的方式)