DesiredCapabilities已过时。

3
我曾经有以下的代码来以不同用户的身份运行驱动程序。
 public static IWebDriver RunIEAsDifferentUser(string User,string Password)
    {

        var capabilitiesInternet = DesiredCapabilities.InternetExplorer();
        capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
        capabilitiesInternet.SetCapability("EnsureCleanSession ", true);
        RunAs("C:\\Exlporer/IEDriverServer.exe", User, Password);
        _webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300));
        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;
    }

问题是我得到了警告:DesiredCapabilities已经过时,我不确定要怎么做才能使其正常工作。

有问题的代码行是:_webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300));。 我尝试将其更改为InternetExplorerOptions caps = new InternetExplorerOptions();。不幸的是,RemoteWebDriver现在只接受Icapabilities

1个回答

7

解决方案在警告消息的结尾处。

对于与Java远程服务器或网格一起使用,请使用InternetExplorerOptions类的ToCapabilites方法。

InternetExplorerOptions options = new InternetExplorerOptions();
options.AddAdditionalCapability("ignoreProtectedModeSettings", true);
options.AddAdditionalCapability("EnsureCleanSession", true);
_webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), options.ToCapabilities(), TimeSpan.FromSeconds(300));

刚刚注意到了,无论如何还是谢谢! :-) - JumpIntoTheWater

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接