user1947415
user1947415

Reputation: 983

The target element corresponds to UI that is no longer available

AE_ComboBox = uia.GetElementByControlTypeAndAutomationId(globalSettings, ControlType.ComboBox, "1");
AE_TargetValue = uia.GetElement(AE_ComboBox, value, true);
SelectionItemPattern SIP = AE_TargetValue.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
SIP.Select();
Thread.Sleep(2000);
SIP.Current.IsSelected

This code throws an exception at the last line.

The target element corresponds to UI that is no longer available (for example, the parent window has closed).
at MS.Internal.AutomationProxies.Misc.ThrowWin32ExceptionsIfError(Int32 errorCode)
at MS.Internal.AutomationProxies.Misc.ProxySendMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Internal.AutomationProxies.WindowsListBox.ListboxItem.System.Windows.Automation.Provider.ISelectionItemProvider.get_IsSelected()

So, what could be the issue here?

Also, another question is, what does "current" mean in SelectionItemPattern? (I am sure it does not mean the current selected element.)

Upvotes: 2

Views: 2808

Answers (2)

Sanjay
Sanjay

Reputation: 345

I also faced the same problem. I was getting automationElement in one line, and accessing it through the Current property in second line. The Current property again goes to the process of target application to get the value when you access it. So during this cross process call, if your UI element may no longer be available, this exception occurs. Even though you have an automationElement object, it will be invalid.

If you just want to get the value, You can try using CacheRequet and then using the Cached property of automationELement object.

Upvotes: 1

AdlerBalduran
AdlerBalduran

Reputation: 1

If you use WPR and the combo is not yet initialized, typically reading items from database which take long time, and accessing the combo you get this exception. So, you need to wait till the combo is initialized in a loop(and sleep maybe)

Upvotes: 0

Related Questions