Gibt es Möglichkeiten, die Proxy-Einstellungen von Firefox einzustellen? Ich habe hier Informationen über FoxyProxy gefunden, aber wenn Selenium funktioniert, sind Plugins im Fenster nicht aktiviert.Webdriver und Proxy-Server für Firefox
Antwort
Blick auf the documentation page.
Tweaking eine bestehende Firefox-Profil
Sie müssen sich ändern "network.proxy.http" & "network.proxy.http_port" Profileinstellungen.
FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference("network.proxy.http", "localhost");
profile.addAdditionalPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);
Einstellungen -> Erweitert -> Netzwerk -> Verbindung (Konfigurieren, wie Firefox mit dem Internet verbindet)
Ich weiß das. Wenn Selenium firefox window for work ausführt, ist die Registerkarte Verbindung mit Proxies leer. – Ockonal
Die WebDriver-API wurde geändert. Der aktuelle Snippet für die Proxy-Einstellung ist
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);
Was ist mit Proxy-Authentifizierung? –
Wert für network.proxy.http_port
sollte integer sein (ohne Anführungszeichen verwendet werden sollen) und network.proxy.type
soll als 1 (ProxyType.MANUAL
, Manuelle Proxy-Einstellungen)
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);
Wenn mir jemand sagen würde, wie ich "user: [email protected]: 2874" im Firefox-Profil einstellen würde, wäre das sehr zu begrüßen. Ich habe versucht, profile.setPreference ("network.proxy.http", "user: [email protected]: 2874") 'aber offensichtlich funktioniert es nicht. – Shane
Was ist mit Proxy-Authentifizierung? –
@Shane: profile.setPreference ("network.proxy.http", "http: // user: [email protected]"), dann sollte profile.setPreference ("network.proxy.http_port", 2874) funktionieren. – learnJQueryUI
Es gesetzt werden i eine andere Lösung ist, suchte, weil ein hatte Probleme mit Code wie folgt (es die System-Proxy in Firefox s eingestellt):
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", "8080");
driver = new FirefoxDriver(profile);
Ich bevorzuge diese Lösung, erzwinge die Proxy-manuelle Einstellung in Firefox. , das zu tun, verwenden Sie die org.openqa.selenium.Proxy Objekt Setup Firefox:
FirefoxProfile profile = new FirefoxProfile();
localhostProxy.setProxyType(Proxy.ProxyType.MANUAL);
localhostProxy.setHttpProxy("localhost:8080");
profile.setProxyPreferences(localhostProxy);
driver = new FirefoxDriver(profile);
wenn es ... helfen könnte
Für PAC basierte Urls
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);
Ich hoffe, das könnte helfen.
Wie authentifizieren Sie sich in diesem Proxy? Ich versuche als "http: // code: Blue% 4019 @ proxypath.pac". Ich kann jedoch keine Seite laden. – codeomnitrix
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);
Es ist für C#
Ich hatte einfach Spaß mit diesem Thema für ein paar Tage und es war schwer für mich, eine Antwort für HTTPS zu finden, also hier ist mein nehmen, für 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 hier: geben Sie einfach die Domain und nicht http://proxy.domain.example.com
, ist der Name der Eigenschaft .ssl
und nicht .https
ich jetzt mit noch mehr fu n versuchen, es zu bekommen, um mich selbst signierten Zertifikate zu akzeptieren ...
Danke, HTTPS funktioniert nur mit diesen Einstellungen – AdamSkywalker
Im Fall, wenn Sie eine URL autoconfig haben -
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);
Hier ist ein Java-Beispiel mit DesiredCapabilities
. Ich habe es zum Pumpen von Selen-Tests in J-Meter verwendet.(Interessierte sich nur für HTTP-Anfragen)
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);
Firefox Proxy: 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);
Nur zu den oben angegebenen Lösungen hinzuzufügen,
Hinzufügen der Liste der Möglichkeiten (Integer-Werte) für. der "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.
So Aufgrund unserer Forderung, der „network.proxy.type“ Wert sollte wie unten erwähnt eingestellt werden.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
WebDriver driver = new FirefoxDriver(profile);
Dies könnte 2010 korrekt gewesen sein, aber die Methode addAdditionalPreference existiert nicht mehr in FirefoxProfile. SetPreference müsste dafür über FirefoxProfile verwendet werden. Zusätzlich, um firefox tatsächlich verwenden zu müssen, muss der Proxy "network.proxy.type" auf 1 gesetzt werden, wie Praveen antwortet, oder 2, wenn es ein PAC wie Saik0 zeigt. Ich benutze die DesiredCapabilities-Methode, wie Dan Seiberts Antwort zeigt. – EGHM