1

我以不同的用户身份运行 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 浏览器,但是将它“连接”到我刚刚打开的现有驱动程序。

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

_webdriverIE = new InternetExplorerDriver();

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

4

1 回答 1

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;
    }
于 2017-03-01T13:19:42.017 回答