Answered by:
ISelectionItemProvider not working for Windows Forms MenuItem?

Question
-
Hi,
I am using UIAutomation to do testing on a Windows Forms application. However apparently, contrary to what's stated here , I can't use element.GetCurrentPattern(SelectionItemPattern.Pattern) on a MenuItem, it throws InvalidOperationException: "Unsupported pattern"
Is there any solution for this? Or did I use the wrong method?
Answers
-
I'm not sure what a 'selectableMenuItem' is.
I looked up MenuItem in MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.menuitem.aspx
There's no property called 'selectable'. There's a property called Checked - I'm assuming that is what you mean.
In managed-client UIA, I don't know of a way to do what you are asking. In the COM client for UIA, which was introduced in Win7 (but is available on Vista and XP, too), you can get GetCurrentPattern to ask for the ILegacyIAccessible pattern, which is a way to drill into the underlying MSAA implementation for MSAA controls.
On that interface, you can call get_CurrentState to get the MSAA state, and STATE_SYSTEM_CHECKED will be set if the menu item is checked.
Thanks,
Michael
This posting is provided "AS IS" with no warranties, and confers no rights.- Proposed as answer by Michael BernsteinMicrosoft employee Friday, January 14, 2011 5:21 PM
- Marked as answer by Michael BernsteinMicrosoft employee Friday, January 28, 2011 5:24 PM
All replies
-
Hi, Louis,
Windows Forms doesn't support UI Automation (it pre-dates UI Automation by several years), so the UI Automation support for Windorms Forms is done through the "MSAA-to-UIA Proxy", which tries its best to translate MSAA to UIA. There's a good discussion on this here. However, not all control patterns are supported through the MSAA-to-UIA Proxy, and in this case, SelectionItem pattern is not supported. (Please see the full list here.) You should be able to use the Invoke Pattern to activate Windows Forms menu items.
Thanks,
Michael
This posting is provided "AS IS" with no warranties, and confers no rights.- Proposed as answer by Michael BernsteinMicrosoft employee Wednesday, January 5, 2011 9:23 PM
- Unproposed as answer by Louis Rhys Thursday, January 6, 2011 3:26 AM
-
Is there a way to check whether a selectable MenuItem is selected or not?
- Edited by Louis Rhys Monday, January 17, 2011 2:12 AM
-
I'm not sure what a 'selectableMenuItem' is.
I looked up MenuItem in MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.menuitem.aspx
There's no property called 'selectable'. There's a property called Checked - I'm assuming that is what you mean.
In managed-client UIA, I don't know of a way to do what you are asking. In the COM client for UIA, which was introduced in Win7 (but is available on Vista and XP, too), you can get GetCurrentPattern to ask for the ILegacyIAccessible pattern, which is a way to drill into the underlying MSAA implementation for MSAA controls.
On that interface, you can call get_CurrentState to get the MSAA state, and STATE_SYSTEM_CHECKED will be set if the menu item is checked.
Thanks,
Michael
This posting is provided "AS IS" with no warranties, and confers no rights.- Proposed as answer by Michael BernsteinMicrosoft employee Friday, January 14, 2011 5:21 PM
- Marked as answer by Michael BernsteinMicrosoft employee Friday, January 28, 2011 5:24 PM
-
-
Hi, Louis,
Here's the MSDN intro for the UI Automation client interfaces:
http://msdn.microsoft.com/en-us/library/ee671216(v=VS.85).aspxYou can use it through managed interop - you can run tlbimp.exe on UIAutomationCore.dll (in the System32 directory) to create an interop library.
Thanks,
Michael
This posting is provided "AS IS" with no warranties, and confers no rights. -
-
It's not all that scary. My blog post on custom patterns (http://blogs.msdn.com/b/winuiautomation/archive/2010/12/08/uia-custom-patterns-part-1.aspx) includes a unit test that does exactly this.
Thanks,
Michael
This posting is provided "AS IS" with no warranties, and confers no rights.