Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu item can only be found after getting GetMainWindow again #598

Open
aristotelos opened this issue Nov 24, 2023 · 2 comments
Open

Menu item can only be found after getting GetMainWindow again #598

aristotelos opened this issue Nov 24, 2023 · 2 comments

Comments

@aristotelos
Copy link

Describe the bug
I have some code that finds a menu item from the current main window. I have observed the following:

  • When I remember the Window returned by GetMainWindow and call FindFirstDescendant on it, it returns null
  • When I call GetMainWindow again after the menu has been clicked and call FindFirstDescendant on that new Window instance returned, it returns the menu item

The element tree was as following:

Window > Menu Bar > Menu Item (clicked) > Menu > Menu Item (to be found and clicked)

Code snippets
This was discovered while working on a FlaUI WebDriver implementation. Here is the part that refreshes the Window all the time to work around this issue:

if (CurrentWindowWithHandle.Window.IsMainWindow)
{
// When expanding menus, calling `GetMainWindow` again is necessary to be able to find the expanded menu items
// This seems to be a bug (it isn't solved by using `CacheRequest.ForceNoCache()`)
return App.GetMainWindow(Automation);
}

Additional context
Using UIA3.

@aristotelos
Copy link
Author

This may be a bug in the Windows UIA3 implementation itself, so that it is impossible to fix in FlaUI. I found the same issue exists in WinAppDriver and the workaround is to re-retrieve the menu item after it has been clicked:

        await TestFixture.cam2DDriver.$(`[name="View"]`).click();
        // WinAppDriver doesn't find $(`[name="Toolbars"]`) straight away
        await TestFixture.cam2DDriver.$(`[name="View"]`).$(`[name="Toolbars"]`).click();
        // WinAppDriver doesn't find $(`[name="${toolbar_name}"]`) straight away
        await TestFixture.cam2DDriver.$(`[name="View"]`).$(`[name="Toolbars"]`).$(`[name="${toolbar_name}"]`).click(); 

@maxinfet
Copy link
Contributor

I have experienced this issue using raw UIAv2 and UIAv3 outside of FlaUI, unfortunately. My guess is that this has something to do with claiming ownership of the windows that menus create but either way it can't be fixed in FlaUI directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants