问题描述
我以前有以下代码,以便以其他用户身份运行驱动程序.
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;
}
问题是我收到警告:DesiredCapabilities is obsolete
,但我不确定要使它继续工作必须做什么.
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.
有问题的行是:_webdriverIE = new RemoteWebDriver(new Uri("http://localhost:5555/"), capabilitiesInternet, TimeSpan.FromSeconds(300));
我尝试将其更改为InternetExplorerOptions caps = new InternetExplorerOptions();
.不幸的是,RemoteWebDriver
现在只接受Icapabilities
.
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.
推荐答案
解决方案位于警告消息的结尾
The solution is at the end of the warning message
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));
这篇关于DesiredCapabilities已过时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!