【问题标题】:DesiredCapabilities is obsoleteDesiredCapabilities 已过时
【发布时间】:2018-05-31 12:11:01
【问题描述】:

我曾经有以下代码,以便以不同的用户身份运行驱动程序。

 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 is obsolete,但我不确定我必须做什么才能保持这个工作。

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

【问题讨论】:

    标签: c# selenium selenium-webdriver desiredcapabilities


    【解决方案1】:

    解决方法在警告信息的最后

    要与 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));
    

    【讨论】:

    • 刚刚注意到.. 还是谢谢! :-)
    猜你喜欢
    • 2019-01-14
    • 2014-07-13
    • 2016-01-01
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 2019-05-30
    相关资源
    最近更新 更多