我正在以不同的用户身份运行IEDriverServer。
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
时,它会打开一个新的驱动程序会话(当然),前一个会话在识别元素等方面没有意义。
_webdriverIE = new InternetExplorerDriver();
我可以将浏览器连接到现有的InternetExplorerDriver
吗?
答案 0 :(得分:1)
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;
}