2012-01-12 50 views
6

我不想給出代理的用戶名/密碼設定我有我的辦公網絡,我可以給代理的瀏覽器之一:如何爲代理包含代理授權用戶名和密碼?

String PROXY = "localhost:8080"; 

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy(); 
proxy.setHttpProxy(PROXY) 
    .setFtpProxy(PROXY) 
    .setSslProxy(PROXY); 
DesiredCapabilities cap = new DesiredCapabailities(); 
cap.setPreference(CapabilityType.PROXY, proxy); 

user_pref("network.proxy.http", "127.0.0.1"); 
user_pref("network.proxy.http_port", 8084); 
user_pref("network.proxy.ssl", "127.0.0.1"); 
user_pref("network.proxy.ssl_port", 8084); 
user_pref("network.proxy.no_proxies_on", "localhost:4444"); 
user_pref("network.proxy.type", 1); 

但是,什麼都我這樣做,它仍然要求Webdriver的密碼。 注意:我可以發送htmlunit驅動程序的用戶名/密碼。請幫忙!

+0

尋求專家的幫助... – 2012-01-15 10:28:55

+0

我覺得你,我試圖找到答案,但沒有運氣。 @Bijoy,已經有一個月了,你有沒有想過要怎麼做?希望你能幫助我。 – Shane 2012-03-03 12:29:44

+0

在當前webdriver(使用firefox驅動程序)中完成它的唯一方法是在firefox配置文件中設置它們,然後使用該配置文件作爲啓動webdriver的源配置文件。我實際上必須修補硒才能在運行時設置它們。我希望能夠提取補丁並在接下來的幾天發佈它們 – 2012-03-15 14:01:55

回答

0

試試下面

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

我看了很多帖子,說明你必須發送輪廓爲Base64編碼字符串。

cap.setPreference(CapabilityType.PROXY, proxy.ToBase64String()); 

我讀過的文檔從來沒有確定過,如果這是必要的,但它值得一試。

相關問題