I am stuck when trying to switch windows using the latest version of webdriver in C#.
I have a base window, when i click a button, it opens a new window.
The target code for this button is as below.
window.open(uri, "DisplayPage", " width=1200, scrollbars=yes , resizable = yes , toolbar = no , menubar = no");
I am using the below mentioned code to target the new window
string BaseWindow = _driver.CurrentWindowHandle;
ReadOnlyCollection<string> handles = _driver.WindowHandles;
foreach (string handle in handles)
{
if (handle != BaseWindow)
{
_driver.SwitchTo().Window(handle).Title.Equals("DisplayPage");
}
}
}
As you can see from above, I am switching to the window using the Target Title from the base window. This does not seem to work.
I then noticed that the Title of the opened window was different, it was "Display - Transaction Page"
I then modified the code to this
string BaseWindow = _driver.CurrentWindowHandle;
ReadOnlyCollection<string> handles = _driver.WindowHandles;
foreach (string handle in handles)
{
if (handle != BaseWindow)
{
_driver.SwitchTo().Window(handle).Title.Equals("Display - Transaction Page");
}
}
}
Still no luck.
Interestingly, I do not get any errors saying "Window not found".
The problem is that When i try to click on elements on the newly opened page, i get a NoSuchElementException which means that the newly opened window has not been targeted.
Any ideas?
Regards,
Hasan