Winappdriver: Session can麓t find childWindow(s)

Created on 24 Jun 2019  路  5Comments  路  Source: microsoft/WinAppDriver

Hi,

i can麓t find the child window of my windows application. I am using WPF. The windows are under the same processes and there is no splashing screen.

I麓ve tried to transfer the solution of #99, but the WindowPopUpFinder throws an timeout error.
I also gave back the window handles, but i just got 1 item, the application itself.

inspec
Here you can see the hierarchy. I am opening the mediaCollectionWindow with a MenuItem.

When I麓m trying this:

            // Open menu 
            WindowsElement menu = _mainWindow.FindElementByAccessibilityId(MAIN_WINDOW.MENU_VIDEO);
            menu.Click();

            // Open modal window via finder
            WindowsElement openVideoWindow = 
(WindowsElement)menu.FindElementByAccessibilityId(MAIN_WINDOW.MENU_ITEM_OPEN_VIDEO);
            PopupWindowFinder finder = new PopupWindowFinder(_mainWindow);
            Thread.Sleep(2000); 
            string videoWindowHandler = finder.Click(openVideoWindow);

            // switch to window
            WindowsDriver<WindowsElement> videoWindow = 
(WindowsDriver<WindowsElement>)_mainWindow.SwitchTo().Window(videoWindowHandler);  

i get the timeout answer as "User-Unhandled"-Exception.

Here i also got an timeout-exception:

            // Open menu 
            WindowsElement menu = 
_mainWindow.FindElementByAccessibilityId(MAIN_WINDOW.MENU_VIDEO);
            menu.Click();

            // Open modal window 
            menu.FindElementByAccessibilityId(MAIN_WINDOW.MENU_ITEM_OPEN_VIDEO).Click();
            Thread.Sleep(2000); 

            // switch to window
            WindowsDriver<WindowsElement> videoWindow = 
(WindowsDriver<WindowsElement>)_mainWindow.SwitchTo().Window(MEDIA_COLLECTION.MEDIA_COLLECTION_WINDOW_TITLE);

And here i got just one item

            ReadOnlyCollection<string> windowHandlesBefore = _mainWindow.WindowHandles; 

            // Open menu 
            WindowsElement menu = _mainWindow.FindElementByAccessibilityId(MAIN_WINDOW.MENU_VIDEO);
            menu.Click();

            // Open modal window
            menu.FindElementByAccessibilityId(MAIN_WINDOW.MENU_ITEM_OPEN_VIDEO).Click();
            Thread.Sleep(2000);

            // Look for windows
            ReadOnlyCollection<string> windowHandlesAfter = _mainWindow.WindowHandles;

And here is the result
windowHandles

FAQ Workaround

Most helpful comment

I ran into similar problem in a .NET Core 3 WPF project. No splash screen. WindowHandles would only return the main window handle even after child windows were opened. The parent/owner was set correctly and I verified with inspect.exe that the new window was in fact a child.

You can, however, interact with the child window elements through the WindowsElement API of the window itself. I was able to use this approach to open an 'About' window through a menu and then close it.

```c#
[Test]
public void TestAboutWindow()
{
// Open About window through menu
_session.FindElementByName("Help").Click();
_session.FindElementByName("About").Click();

// Close child window through WindowElement API
var aboutWindow = _session.FindElementByName("AboutWindow");
aboutWindow.FindElementByName("Close").Click();

}
```

All 5 comments

  1. Try using the WinAppDriver UI Recorder instead of inspect.exe.
  2. Try accessing the child window through a desktop session, maybe it is fired from the WPF application window but it is not a child of the window.

@naeemakram thank you for your fast answer. The second answer didn麓t work, i have the same problem (empty window collection and timeout).
But i guess there is another problem. I am using Windows Server 2016. Does the desktop session work here too?

I tried this:

            // TODO: from desktop Session
            WindowsDriver<WindowsElement> desktopSession = WindowSession.StartDesktopSession();
            desktopSession.Keyboard.PressKey(OpenQA.Selenium.Keys.Command + "a" + OpenQA.Selenium.Keys.Command);
            var collection = desktopSession.WindowHandles; 
            desktopSession.SwitchTo().Window(MEDIA_COLLECTION.MEDIA_COLLECTION_WINDOW); 

And got empty collection of window
windowHandles

I outsourced the connection code:

        public static WindowsDriver<WindowsElement> StartDesktopSession()
        {
            return new WindowsDriver<WindowsElement>(new Uri("http://10.128.190.109:4723/wd/hub"), 
            SetDesktopCapabilities());
        }

        private static DesiredCapabilities SetDesktopCapabilities()
        {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.SetCapability("app", "Root");

            return capabilities; 
        }

I'm sorry, I can't say for sure since I haven't tried on Windows Server 2016.
Which version of WinAppDriver are you using? I remember someone had a problem finding windows using desktop session in recent stable release(1.1). If you're using the stable release, try using the pre-release version i.e. 1.1.1.

I ran into similar problem in a .NET Core 3 WPF project. No splash screen. WindowHandles would only return the main window handle even after child windows were opened. The parent/owner was set correctly and I verified with inspect.exe that the new window was in fact a child.

You can, however, interact with the child window elements through the WindowsElement API of the window itself. I was able to use this approach to open an 'About' window through a menu and then close it.

```c#
[Test]
public void TestAboutWindow()
{
// Open About window through menu
_session.FindElementByName("Help").Click();
_session.FindElementByName("About").Click();

// Close child window through WindowElement API
var aboutWindow = _session.FindElementByName("AboutWindow");
aboutWindow.FindElementByName("Close").Click();

}
```

Yeah, this way is still working. Sadly, I didn't tried the Version 1.1.1. I will do it on December, when I not need to use my working laptop :smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jsa34 picture jsa34  路  3Comments

Iziksh picture Iziksh  路  3Comments

didhddldlq picture didhddldlq  路  3Comments

hassanuz picture hassanuz  路  4Comments

SimonKirkhamCL4U picture SimonKirkhamCL4U  路  3Comments