2017-03-01 41 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; 
    } 
相關問題