2017-03-01 2 views
1

IEDriverServer를 다른 사용자로 실행 중입니다.IE 브라우저를 열고 기존 IEDriverServer에 "연결"하십시오.

RunAs("C:\\Exlporer/IEDriverServer.exe", "User","Password"); 
     _webdriverIE = new InternetExplorerDriver(); 
     var CustomerPage = new CRMLogin(_webdriverIE).GoToCRMURL("http://foo.com"); 

public void RunAs(string path, string username, string password) 
{ 
    ProcessStartInfo myProcess = new ProcessStartInfo(path); 
    myProcess.UserName = username; 
    myProcess.Password = MakeSecureString(password); 
    myProcess.UseShellExecute = false; 
    myProcess.LoadUserProfile = true; 
    myProcess.Verb = "runas"; 
    myProcess.Domain = "DOM001"; 
    Process.Start(myProcess); 
} 

public SecureString MakeSecureString(string text) 
{ 
    SecureString secure = new SecureString(); 
    foreach (char c in text) 
    { 
     secure.AppendChar(c); 
    } 

    return secure; 
} 

IE 브라우저를 열고 싶지만 방금 연 기존 드라이버에 "연결"하고 있습니다.

InternetExplorerDriver에 호출 할 때, 그것은 드라이버 (물론)과 이전의 새로운 세션을 엽니 다

_webdriverIE = new InternetExplorerDriver(); 

는 내가에 브라우저를 연결할 수 있습니다 .. 인식 요소 등의 측면에서 의미가 없습니다 기존 InternetExplorerDriver?

답변

1

트릭을 발견했습니다.

public static IWebDriver RunIEAsDifferentUser(string User,string Password) 
    { 
     RunAs("C:\\Exlporer/IEDriverServer.exe", User, Password); 
     _webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), DesiredCapabilities.InternetExplorer(), TimeSpan.FromSeconds(180)); 
     return _webdriverIE; 

    } 
    public static void RunAs(string path, string username, string password) 
    { 
     ProcessStartInfo myProcess = new ProcessStartInfo(path); 
     myProcess.UserName = username; 
     myProcess.Password = MakeSecureString(password); 
     myProcess.UseShellExecute = false; 
     myProcess.LoadUserProfile = true; 
     myProcess.Verb = "runas"; 
     myProcess.Domain = "DOM001"; 
     Process.Start(myProcess); 
    } 

    public static SecureString MakeSecureString(string text) 
    { 
     SecureString secure = new SecureString(); 
     foreach (char c in text) 
     { 
      secure.AppendChar(c); 
     } 

     return secure; 
    } 
관련 문제