Webdriver и прокси-сервер для firefox

есть ли способы настройки прокси в Firefox? Я нашел здесь информацию о FoxyProxy, но когда селен работает, Плагины неактивированы в окне.

12 ответов


посмотреть на странице документации.

настройка существующего профиля Firefox

вам нужно изменить сеть".полномочие.сеть http"&".полномочие.http_port" настройки профиля.

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

значение 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);

Я просто повеселился с этой проблемой в течение нескольких дней, и мне было трудно найти ответ на 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);

Gotchas здесь: введите только домен, а не http://proxy.domain.example.com имя свойства .ssl, а не .https

теперь мне еще больше нравится пытаться заставить его принять мои самоподписанные сертификаты...


API WebDriver был изменен. Текущий фрагмент для установки прокси-сервера -

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

просто добавьте к приведенным выше решениям.,

добавление списка возможностей (целочисленных значений) для "сети.полномочие.тип."

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

в случае если у вас есть 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);

вот пример 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); 

для URL на основе 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);

Я надеюсь, что это может помочь.


Прокси 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);

есть еще одно решение, которое я искал, потому что у него были проблемы с таким кодом (он установил системный прокси в firefox):

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

Я предпочитаю это решение, оно заставляет ручную настройку прокси-сервера в firefox. Для этого используйте организацию.openqa.селен.Прокси-объект для настройки Firefox :

FirefoxProfile profile = new FirefoxProfile();
localhostProxy.setProxyType(Proxy.ProxyType.MANUAL);
localhostProxy.setHttpProxy("localhost:8080");
profile.setProxyPreferences(localhostProxy);
driver = new FirefoxDriver(profile);

, если это может помочь...


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#


Настройки - > Дополнительно - > сеть - > подключение (настройка подключения Firefox к интернету)