2014-03-28 92 views
2

我在我的C#winforms應用程序中使用Selenium WebDriver。我在aoutologin有一個問題。 打開Firefox彈出警報輸入字段的用戶名和密碼。Selenium WebDriver自動登錄代理用戶名和密碼

var profile = new FirefoxProfile(); 
profile.SetPreference("general.useragent.override", [UserAgent]); 

       Proxy proxy = new Proxy(); 
       proxy.HttpProxy = proxy; 
       proxy.FtpProxy = proxy; 
       proxy.SslProxy = proxy; 
       proxy.SocksProxy = proxy; 
       proxy.SocksUserName = username; 
       proxy.SocksPassword = password; 
       profile.SetProxyPreferences(proxy); 
       profile.SetPreference("network.websocket.enabled", false);      

       IWebDriver driver = new FirefoxDriver(profile); 
       driver.Url = siteUrl; 

回答

0

您將需要使用AutoIT腳本。

WinWait("Authentication Required","","20") 
If WinExists("Authentication Required") Then 
    WinActivate("Authentication Required") 
    Send($CmdLine[1]) 
    Send("{TAB}") 
    Send($CmdLine[2]) 
    Send("{ENTER}") 
EndIf 

我也在研究另一個使用firefox的解決方案:cnofig屬性來解決這個問題。如果我想出點什麼,會讓你知道。

1

請嘗試下面的代碼先設置代理,然後設置自動登錄。

firefoxProfile.SetPreference("network.proxy.type", 1); 
firefoxProfile.SetPreference("network.proxy.http", "add server name"); 
firefoxProfile.SetPreference("network.proxy.http_port", 8080); 
firefoxProfile.SetPreference("network.proxy.ssl", "add server name"); 
firefoxProfile.SetPreference("network.proxy.ssl_port", 8080); 
firefoxProfile.SetPreference("network.proxy.no_proxies_on", "add website url(s)"); 

Driver = new FirefoxDriver(firefoxProfile); 

希望這會對你有用。

感謝, Anshul

0
 String PROXY = "http://login:[email protected]:port"; 
     ChromeOptions options = new ChromeOptions(); 

     options.AddArguments("user-data-dir=path/in/your/system"); 

     Proxy proxy = new Proxy(); 

     proxy.HttpProxy = PROXY; 
     proxy.SslProxy = PROXY; 
     proxy.FtpProxy = PROXY; 

     options.Proxy = proxy; 

     // Initialize the Chrome Driver 
     using (var driver = new ChromeDriver(options))