FlaUI / FlaUI

UI automation library for .Net
MIT License
2.23k stars 365 forks source link

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

Open aristotelos opened 10 months ago

aristotelos commented 10 months ago

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

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:

https://github.com/FlaUI/FlaUI/blob/b1f61c11489e8c3ea40be38628f4d15bcc1c7a1d/src/FlaUI.WebDriver/Session.cs#L49-L54

Additional context Using UIA3.

aristotelos commented 6 months ago

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 commented 4 months ago

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.