C# - AutomationElement.FromHandle(IntPtr) giving exception even after windowhandle is fetched.

0

TIMEOUT = 20000

m_CurrentApplicationAlias = appAlias;
            **m_RunningApplicationsDic[appAlias].FocusProcessMainWindow(TIMEOUT);**

public bool FocusProcessMainWindow(uint timeout)
    {
        **MUIA_Window mainWindow = GetProcessMainWindow(timeout);**
        if (mainWindow != null)
        {
           // mainWindow.Focus();
            mainWindow.SetForegroundWindow(ProcessId, Process.MainWindowHandle);
            mainWindow.MaximizeWindow();
            return true;
        }

        return false
  }

public MUIA_Window GetProcessMainWindow(uint timeout)
    {
        if (WaitForMainWindow(timeout))
        {
            LogManager.Log("mainwindowhandle {0}", m_process.MainWindowHandle);
            **return new MUIA_Window(AutomationElement.FromHandle(m_process.MainWindowHandle));
        }**
        else
            return null;
    }

LOGS :

waiting to get windowhandle

20180116-17:04:48.882 - windowhandle has been fetched & it is: 2754322

20180116-17:04:48.882 - mainwindowhandle 2754322

01/16/2018 17:04:48 887 1 [ERR] Current Application not found. You may need to switch to any applicationcannot switch to application: DefaultJobManager

01/16/2018 17:04:48 914 1 [ERR] Exception : System.Windows.Automation.ElementNotAvailableException: Element not available ---> System.Runtime.InteropServices.COMException: An event was unable to invoke any of the subscribers (Exception from HRESULT: 0x80040201)

c#
exception
automation
ui-automation
asked on Stack Overflow Jan 18, 2018 by Shahan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0