2012-08-29 3 views
6

프록시 서버에서 인증이 필요한 경우 아래 코드에서 프록시 서버 매개 변수를 설정하면 FireFox에서 인증 대화 상자가 나타나며 기본적으로 자동으로 채울 수 없습니다. 어쨌든 설정할 수 있습니까 사용자 이름비밀 번호?C# 셀레늄 WebDriver FireFox 프로필 - 인증을 통한 프록시 사용

FirefoxProfile profile = new FirefoxProfile(); 
String PROXY = "192.168.1.100:8080"; 
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); 

당신이 http://username:[email protected]:8080 처럼 뭔가 프록시 문자열의 형식을 시도 할 경우 해당 문자열을 오류 얻을이 잘못되었습니다. 그래서 나는 이것을 성취 할 수있는 방법이 있어야한다고 생각합니다.

도움을 주시면 감사하겠습니다.

+0

아직 프록시 서버에서 인증을 비활성화하고 IP 범위로 허용 했으므로 지금은이 답변을 찾지 못했습니다. – Tim

+0

'ProfilesIni'에 필요한 참조가 무엇입니까?'형식 또는 네임 스페이스 이름 'ProfilesIni'을 (를) 찾을 수 없습니다. ' –

답변

0

프로필을 만들고 프로필에 인증 데이터를 저장하면됩니다. 프로필은 사용자가 초기화에 코드에서 선택할 수 있습니다 "webdriver"라고하는 경우 :

ProfilesIni allProfiles = new ProfilesIni(); 
FirefoxProfile profile = allProfiles.getProfile("WebDriver"); 
profile.setPreferences("foo.bar",23); 
WebDriver driver = new FirefoxDriver(profile); 
+0

매우 흥미 롭습니다. 작동한다면 다시 시도해야합니다. – Tim

+0

좋아요! 제발 알려주십시오 :) –

+0

ProfilesIni는 어떤 네임 스페이스입니까? :/... –

2
 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)) 
0

은 AutoIt이없이 MS UI 자동화로 했 :

public void AuthInProxyWindow (string login, string pass) 
    { 
     var proxyWindow = AutomationElement.RootElement 
      .FindFirst(TreeScope.Subtree, 
       new PropertyCondition(AutomationElement.ClassNameProperty, "MozillaDialogClass")); 

     var edits = proxyWindow.FindAll(TreeScope.Subtree, 
      new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); 

     var unamePoint = edits[1].GetClickablePoint(); 
     Mouse.MoveTo(new Point((int) unamePoint.X, (int) unamePoint.Y)); 
     Mouse.Click(MouseButton.Left); 

     SendKeys.SendWait(login); 
     var pwdPoint = edits[2].GetClickablePoint(); 
     Mouse.MoveTo(new Point((int) pwdPoint.X, (int) pwdPoint.Y)); 
     Mouse.Click(MouseButton.Left); 
     SendKeys.SendWait(pass); 

     Keyboard.Press(Key.Return); 
     Logger.Debug("Authefication in Firefox completed succesfully"); 
    } 

마우스 Microsoft.TestApi로 이동

관련 문제