In my scenario, I'm verifying whether clicking on a link navigates to another page (verifying for the page title). IE, FF and chrome return 2 as expected but Opera returns 4. I didn't have any other Opera instances opened at the time of running tests. It clicks on the link and required page is opened but WindowHandles returns 4.
Code:
string BaseWindow = Drivers._driverInstance.CurrentWindowHandle;
Drivers._driverInstance.SwitchTo().Frame(Drivers._driverInstance.FindElement(By.ClassName("iframe-fix")));
if (Drivers._driverInstance.GetType().Name.ToString() == "InternetExplorerDriver")
{
IJavaScriptExecutor js = (IJavaScriptExecutor)Drivers._driverInstance;
js.ExecuteScript("arguments[0].click();", Drivers._driverInstance.FindElement(By.LinkText("Professional Services.")));
}
else
{
Drivers._driverInstance.FindElement(By.LinkText("Professional Services.")).Click();
}
System.Collections.ObjectModel.ReadOnlyCollection<string> handles = Drivers._driverInstance.WindowHandles;
if (handles.Count == 2)
{
foreach (string handle in handles)
{
if (handle != BaseWindow)
{
string title = Drivers._driverInstance.SwitchTo().Window(handle).Title;
Assert.AreEqual("title of the page", Drivers._driverInstance.Title);
}
}
}
else
{
Assert.Fail("WindowHandles returns " + handles.Count + " instead of 2");
}
Drivers._driverInstance.SwitchTo().Window(BaseWindow);
Can someone suggest why Opera returns 4 instead of 2.
Thanks.
The Opera driver doesn't return the right number of handles. This issue has already been reported to the project but it seems that the project is no longer maintained:
https://github.com/operasoftware/operachromiumdriver/issues/15