I have one already opened IE browser , with some url. After this, I Run below code which will open another IE browser. however it gives me only one window handle in below code. Is it possible to get previously opened IE browser handle ?
IWebDriver IEdriver = new InternetExplorerDriver();
IReadOnlyCollection<String> browsers = IEdriver.WindowHandles;
foreach (String item in browsers)
{
IEdriver.SwitchTo().Window(item);
String url = IEdriver.Url;
}
Be careful as what you are trying to do, is not robust solution to write tests cases. If one test case causes browser to crash you will be getting all the test cases failed.
Also I don't think it should be possible to get handles on previously opened window by default, because when you write code
It calls for a constructor of InternetExplorerDriver class and opens new instance of Internet Explorer.
You can either go for close all browsers before starting your test case execution by killing the ie process from task manager.
I think this is what you're looking for: