If System.Diagnostics.Process.Start("IEXPLORE.EXE", url); opens a new browser session, how do you open a new browser window in an existing version of internet explorer?
Thanks
Try Process.start(url) it will open up a new Tab if browser is already running, otherwise it will open default browser and shows the Page.
Check this out
Activate existing browser window with given URL from C# application (without triggering reload)
Hope that helps
Related
I am trying to automate citrix login process at my organization.
I am using ChromeDriver ( selenium ) to automate few steps which is successful till now.
But it downloads .ica file which I need to double click and which opens fresh IE browser instance.
I am not able to get handle of this instance. I want to enter username and password programmatically in this newly opened IE window.
My code is as below.
// Code which downloads ica file
var idCitrix = chromedriver.FindElementById("IdOfDOMElement");
idCitrix.Click();
// Below code will ALWAYS OPEN IE FRESH BROWSER INSTANCE (IE 11)
Process.Start("LOCATION OF .ICA FILR FROM DOWNLOADS FOLDER");
//How to get handle of this newly opened IE window ??
I am using Selenium to simulate a user to automate some legacy software. The software works only with IE6 (I'm using IE11 in compatibility mode) and is a bit crap.
There is a point in the software where the Windows Security dialog appears. This requires credentials before the user/simulator can proceed.
I'm using IAlert.SetAuthenticationCredentials to try and populate the dialog but this doesn't seem to work. To move on from this, I can enter the details manually, but then Selenium seems to thing the main browser window has been closed:
Currently focused window has been closed.
The WindowHandles collection at this point is empty, but the browser window is still open, and has rendered the correct page.
What's going on here?
UPDATE
The answers provided are suggestions on how to handle the dialog. I'm wondering why Selenium thinks the browser window is closed when in fact it is still there.
It is not possible to interract with native windows via selenium. The way to deal with your issue is for example to use analogue of Robot in Java. Since you are using C# there is a simulator here https://www.codeproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library.
Example code would be like following:
// Simulate (Ctrl + C) shortcut, which is copy for most applications
KeyboardSimulator.SimulateStandardShortcut(StandardShortcut.Copy);
// This does the same as above
KeyboardSimulator.KeyDown(Keys.Control);
KeyboardSimulator.KeyPress(Keys.C);
KeyboardSimulator.KeyUp(Keys.Control);
There are also Mouse simulators, so with this framework it will be possible to enter the required values in window and accept it.
Try to switch to that alert by,
var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("Username", "Pwd");
alert.Accept();
I have tested it and it works for IE11, selenium v3.1.0
Ref: https://seleniumhq.github.io/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_IAlert_SetAuthenticationCredentials.htm
Suggesstion 1-Go to internet explorer settings->security settings-> user authentication-> select automatic login with current username and password.
Suggesstion 2- if your application has access to it's API, then login via API, get the authentication token and set the auth.token in browser cookie.
When you type javascript:window.open('http://stackoverflow.com') in chrome's navigation bar, it opens new tab. I want same, but when running chrome from cmd:
var process = Process.Start("chrome.exe",
"javascript:window.open('http://stackoverflow.com')");
I'm doing this because I want to close that window later from inside it with window.close(). If I open website directly, error is thrown:
Scripts may close only the windows that were opened by it.
If you just want chrome to open a new tab to a page, why not try:
var process = Process.Start("chrome.exe", "http://stackoverflow.com");
If you just want to close the window later with JS, what about:
window.open(location, '_self', '');
window.close();
Note, you cannot automatically add the javascript prefix to a chrome URL, even with copy and paste - this is a security feature.
see - Javascript stripped from URL bar?
I'm trying to use Selenium WebDriver to automatically login in to a site with a user-name and password. I've done my research and I don't believe this feature is supported by WebDriver, so I need to find another way. The site I'm trying to automate logging into is located here.
When prompted to login a popup window comes up that doesn't seem to be part of the browser. I'm using Firefox and Chrome. It seems Windows API may be required? I already tried passing the credentials in the URL but that didn't work. Also tried sendkeys, but received a Windows exception that the application was not accepting Windows messages. I also tried switching the current handle using driver.windowhandles but the popup doesn't seem to be a new handle.
Does anybody have any ideas? I'm kinda stuck. The preliminary code to get to the popup window is:
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.portal.adp.com");
string currentWindow = driver.CurrentWindowHandle;
IWebElement userLogin = driver.FindElement(By.Id("employee"));
userLogin.Click();
The popup you are seeing is prompted by web server and is a authentication prompt. Selenium doesn't support this operation.
One of the way to handle this limitation is to pass user and password in the url like like below:
http://user:password#example.com
More info available here : http://aleetesting.blogspot.in/2011/10/selenium-webdriver-tips.html
I wanted my answer out there because I think I've solved it. This answer does not require passing the credentials through the URL (for those of you that are unable to like me). It also does not require any custom Firefox Profiles or extensions to be installed or included with the solution or installed onto the browser eliminating cross-machine compatibility issues.
The issue with me was that the authentication could not be completed via passing the credentials through the URL because the login was behind a proxy.
So, I turned to windows automation toolkits and found AutoIT. Using AutoIT and Selenium, you can login automatically by sending the username and password to the windows dialog that appears. Here's how (note the steps below are for c#:
1 - Download AutoIT from http://www.autoitscript.com/site/autoit/downloads/
2 - Add the autoit .dll to your project references.
Right click on references, select Add Reference. Next click the browse button and browse to the dll location (most default installations it will be c:\Program Files (x86)\AutoIt3\AutoItX\AutoItX3.dll), and add to project.
3 - use AutoIT and Selenium like this (assuming your web driver is already initialized):
//Initialize AutoIT
var AutoIT = new AutoItX3();
//Set Selenium page load timeout to 2 seconds so it doesn't wait forever
Driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(2));
//Ingore the error
try
{
Driver.Url = url;
}
catch
{
return;
}
//Wait for the authentication window to appear, then send username and password
AutoIT.WinWait("Authentication Required");
AutoIT.WinActivate("Authentication Required");
AutoIT.Send("username");
AutoIT.Send("{TAB}");
AutoIt.Send("password");
AutoIT.Send("{ENTER}");
//Return Selenium page timeout to infinity again
Driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(-1));
Anyway, that's it, and it works like a charm :)
Also note that there are some special characters that need to be escaped in AutoIT using the sequence "{x}". For example, if your password is "!tRocks", you'd need to pass it into AutoIT as "{!}tRocks".
Happy automating.
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.http.phishy-userpass-length", 255);
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", hostname);
Driver = new FirefoxDriver(profile);
hostname is your URL (example.com) then try to
Driver.Navigate().GoToUrl(http://user:password#example.com);
I just got done working on a prototype project that is supposed to handle exactly this kind of situation.
It utilizes BrowserMob, a popular open source proxy, to perform the authentication.
SeleniumBasicAuthWrapper Hope it helps! It is still a work in progress, but hopefully we'll get any kinks or defects ironed out in the near future.
Hey SO, is there anyway I can use HtmlPage.Window.Navigate(new Uri(link), "_blank"); to open a URI in a new tab (not new window!) which is in the same instance of Internet Explorer.
Currently using SL3 and it seems that whether its a new tab vs. new window is based on browser options...
Any help? Thanks.
You're doing it properly by using "_blank". What that does is opens a new page in either a new tab or window depending on the user's settings:
Internet Explorer Settings
Firefox
Safari
If you want to use a "hack" to get around this use this link as a resource. It basically states that until a browser supports CSS3 you'll have to use a "hack" as a workaround:
Internet Explorer -- IWebBrowser2::Navigate2 (use 0x1000 as the second parameter). Note: you have to have FULL TRUST MODE for this to work.