打开 IE 浏览器并 "connect" 到现有的 IEDriverServer

open IE browser and "connect" to existing IEDriverServer

我是 运行 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浏览器,但是"connecting"它变成了我刚刚打开的现有驱动程序。

当调用InternetExplorerDriver时,它会打开一个新的驱动程序会话(当然),而之前的会话在识别元素等方面没有任何意义。

_webdriverIE = new InternetExplorerDriver();

我可以将浏览器连接到现有的 InternetExplorerDriver 吗?

找到窍门了。

  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;
    }