2017-03-01 18 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(); 

私はANにブラウザを接続することができます既存の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; 
    } 
関連する問題