首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打开IE浏览器并“连接”到现有的IEDriverServer

打开IE浏览器并“连接”到现有的IEDriverServer
EN

Stack Overflow用户
提问于 2017-03-01 16:34:53
回答 1查看 468关注 0票数 1

我以另一个用户的身份运行IEDriverServer。

代码语言:javascript
复制
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时,它会打开一个新的驱动程序会话(当然),而前一个会话在识别元素等方面没有任何意义。

代码语言:javascript
复制
_webdriverIE = new InternetExplorerDriver();

是否可以将浏览器连接到现有的InternetExplorerDriver

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-01 21:19:42

找到诀窍了。

代码语言:javascript
复制
  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;
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42526838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档