Reputation: 1336
I'm running IEDriverServer as a different user.
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;
}
I would like to open the IE browser, but "connecting" it to the existing driver I just opened.
When calling to InternetExplorerDriver
, it opens a new session of the driver (of course) and the previous one has no meaning in terms of recognize elements etc..
_webdriverIE = new InternetExplorerDriver();
can I connect the browser to an existing InternetExplorerDriver
?
Upvotes: 1
Views: 512
Reputation: 1336
found the trick.
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;
}
Upvotes: 1