Can't Pass by Invoke that Opens Window
Hello, I am trying to use FlaUI to automate a software. I get the main window and I can operate with the menus.
The issue is that I get a menuitem and I invoke it, and the invoke locks the current thread. I have tried to call it using a different thread as in the example below, but then it is the next find that does not work (the one with the retry).
The invoke works. In my target application a modal form is shown. But the I can't continue accessing this form as the thread gets locked.
How can I invoke the menu, open the window and continue working?
Thank you,
var mainWindow = sapApp.GetMainWindow(automation);
FlaUI_CloseAllSecondaryWindows(mainWindow);
mainWindow.Focus();
FlaUI.Core.Input.Keyboard.TypeSimultaneously(VirtualKeyShort.ALT, VirtualKeyShort.KEY_F);
Thread.Sleep(1000);
FlaUI.Core.Input.Keyboard.TypeSimultaneously(VirtualKeyShort.ALT, VirtualKeyShort.KEY_E);
Thread.Sleep(1000);
FlaUI.Core.Input.Keyboard.TypeSimultaneously(VirtualKeyShort.ALT, VirtualKeyShort.KEY_T);
Thread.Sleep(1000);
var menustrip = mainWindow.FindFirstChild(cf => cf.ByAutomationId("msMain")).AsMenu();
var filemenu = menustrip.FindFirstChild(cf => cf.ByName("File")).AsMenuItem();
var exportmenu = filemenu.FindFirstChild(cf => cf.ByName("Export")).AsMenuItem();
var exportS2K = exportmenu.FindFirstChild(cf => cf.ByName("SAP2000 .s2k Text File...")).AsMenuItem();
Task openExportFormTask = new Task(() => { exportS2K.Invoke(); });
// Gets the export window
var exportWindowRetry = Retry.WhileNull(() => mainWindow.FindFirstChild(cf => cf.ByAutomationId("DBTableForm")),
timeout: TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(200), throwOnTimeout: false, ignoreException: false);
if (!exportWindowRetry.Success) throw new S2KHelperException("Could not get the Export Form.");
FlaUI.Core.AutomationElements.Window exportWindow = exportWindowRetry.Result.AsWindow();
I am missing some code where you start and await the task. Another input could be to use Click as this does not block. But using invoke in a task should work fine.
@scudelari Did you find a solution?
Work round for me
var flag = false;
AutomationElement.RegisterAutomationEvent(
AutomationElement.Automation.EventLibrary.Invoke
.InvokedEvent, TreeScope.Element, (_, _) => { flag = true; });
Retry.WhileFalse(() =>
{
AutomationElement.Click();
return flag;
}, TimeSpan.FromSeconds(3), ignoreException: true, throwOnTimeout: true);
return this;