有沒有什麼方法可以設置Firefox的代理設置?我在這裏找到關於FoxyProxy的信息,但是當Selenium工作時,插件在窗口中未被激活。用於Firefox的網絡驅動器和代理服務器
回答
調整現有的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);
首選項 - >高級 - >網絡 - >連接(Firefox的配置如何連接到互聯網)
我知道這一點。當Selenium運行firefox窗口工作時,帶代理的連接選項卡是空的。 – Ockonal 2010-05-23 04:05:41
WebDriver API已更改。設置代理服務器的當前片段是
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "localhost");
profile.setPreference("network.proxy.http_port", "3128");
WebDriver driver = new FirefoxDriver(profile);
代理身份驗證如何? – 2012-03-06 18:33:08
爲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);
如果有人告訴我如何在firefox個人資料中設置「user:[email protected]:2874」,將會非常感激。我試過'profile.setPreference(「network.proxy.http」,「user:[email protected]:2874」)'但顯然這是行不通的。 – Shane 2012-03-03 12:41:07
代理身份驗證怎麼樣? – 2012-03-06 18:33:17
@Shane:profile.setPreference(「network.proxy.http」,「http:// user:[email protected]」),然後profile.setPreference(「network.proxy.http_port」,2874)應該工作。 – learnJQueryUI 2013-05-13 01:53:43
有是另一種解決方案,我期待因爲這樣的代碼有問題(它在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對象設置火狐:
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);
希望這可能有所幫助。
如何在此代理中進行身份驗證?我正在嘗試'http:// code:Blue%4019 @ proxypath.pac'。但我無法加載任何頁面。 – codeomnitrix 2013-06-20 09:07:54
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
現在我有更多的福ñ試圖讓它接受我的自簽名的證書......
謝謝,HTTPS只適用於這些設置 – AdamSkywalker 2016-05-19 15:50:56
在情況下,如果你有一個自動配置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請求興趣)
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);
火狐代理: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」。
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);
- 1. 遠程網絡驅動程序:在Chrome和Opera中使用代理服務器
- 2. 設置量角器的網絡驅動器/硒服務器
- 3. Can Plastic SCM服務器使用網絡驅動器?
- 4. 處理Firefox的安全警告中硒的網絡驅動器
- 5. XP_FileExists不適用於網絡驅動器
- 6. 從網絡服務器複製目錄到映射的網絡驅動器
- 7. 清理斷開的網絡驅動器
- 8. Windows服務和Dll在網絡驅動器
- 9. 適用於網絡服務器的SSL
- 10. JasperSoft服務器導出到網絡驅動器
- 11. 從FTP服務器下載文件到網絡驅動器
- 12. 共享文件夾/網絡驅動器服務器2008
- 13. 映射要由服務使用的網絡驅動器
- 14. 在網絡瀏覽器控制中使用代理服務器
- 15. 無法使用量角器網絡驅動器管理器
- 16. 如何使用谷歌驅動器像一個網絡服務
- 17. 如果通過服務映射網絡驅動器不可用
- 18. 映射網絡驅動器
- 19. 從網絡驅動器
- 20. 網絡驅動器標籤
- 21. 映射網絡驅動器
- 22. 映射網絡驅動器
- 23. cfdirectory網絡驅動器
- 24. 與網絡驅動器
- 25. 創建網絡驅動器
- 26. 使用php從C驅動器自動上傳到網絡服務器
- 27. Tomcat的Windows服務無法訪問網絡驅動器
- 28. nginx是反向代理和網絡服務器
- 29. Hudson bAt腳本和網絡驅動器
- 30. c# - folderBrowserDialog1和網絡驅動器
這在2010年可能是正確的,但addPolicyPreference方法不再存在於FirefoxProfile中setPreference將不得不通過FirefoxProfile來完成。此外,爲了讓Firefox實際使用代理「network.proxy.type」需要設置爲1,如Praveen回答提及,或者如果其PAC爲Saik0,則設置爲2。 Dan Seibert的回答顯示,我使用DesiredCapabilities的方法來做到這一點。 – EGHM 2015-12-23 03:01:11