DesiredCapabilities is obsolete

為{幸葍}努か 提交于 2019-12-07 17:02:22

问题


I used to have the following code in order to run the driver as different user.

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

The thing is that I'm getting warning :DesiredCapabilities is obsolete and I'm not sure what I have to do in order to keep this working.

The problematic line is : _webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300)); I have tried changing it to InternetExplorerOptions caps = new InternetExplorerOptions();. Unfortunately , the RemoteWebDriver only accept Icapabilities now.


回答1:


The solution is at the end of the warning message

For use with the Java remote server or grid, use the ToCapabilites method of the InternetExplorerOptions class.

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


来源:https://stackoverflow.com/questions/47863579/desiredcapabilities-is-obsolete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!