UiSpy - no selectors for menu in Notepad

Hi, this is actually the reason for my question in another post about sending keys like Control, Shift, Alt, Win, CapsLock, LeftArrow, RightArrow, UpArrow, DownArrow, and so on. Although I can grab the Notepad MenuBar itself, none of the children (e.g. ‘File’, ‘Edit’, ‘Format’, ‘View’, or ‘Help’) are available.

UiSpyMenuBar

MenuBarSelectors

However, for MS Word, I am able to grab similar elements (e.g. ‘File’ button).

Using modifier keys to access menu elements is often easier in automation than using selectors, so even if the Menu bar remains inaccessible (for whatever reason) in Notepad, it would be a welcome workaround.

Regards,
burque505

Hello @burque505,

In my case UISpy can grab each and every element of the Notepad windows application.
It is a bit of a wildcard and we are currently working on fixing the bug.
For now you are right, the best approach would be a workaround.
Could you describe me a bit more your use case?
What do you want to do?

Best regards,
J.


James Papadimitriou

1 Like

Sure, Win7 Pro 64-bit, just as a first-steps script I wanted to click the File menu, open a file, enter some text in the Edit control, and save it. But all I can grab is the Menubar.

‘Alt-F’ + ‘O’ should get me there, but so far no joy with modifier keys.

I just acquired a new Win10 machine, and I have not tried it on that yet. I will now, and report any better results.

EDIT: On Win10 I can’t access any menu items with UiSpy either.
Regards,
burque505

1 Like

Could you try launching both UISpy and Notepad with admin rights?

Best regards,
James


James Papadimitriou
Technical Evangelist

1 Like

Hi, I tried that, but no luck. I have the impression (possibly harebrained :grinning:) that the problem (which exists with Calculator also) may be that UiSpy is treating ‘Menubar’ not as a MenuBar, but as a ‘Menu’ item. I have some evidence tending to support this. Consider this selector for the Calculator ‘View’ menu on the menubar, which was kludged together by first adding a MenuBar control and then editing it using the Custom Selector window:

image

(This of course has the associated screen image of its parent, the MenuBar, since it was created from it.) EDIT: “Should not ‘View’ be a ‘menu’, and not a ‘menuitem’?” WRONG: :confounded:All UiAutomation “Spy” programs I’ve tested refer to the ‘View’ entry on the MenuBar as a ‘menuitem’. I stand corrected.

Using the selector created as above, the following code will click on the “View” menu, and you can see it flicker briefly.

Import                              "C:\Users\admin\Documents\Robin\Calc4.appmask"

System.RunApplication               ApplicationPath:  'C:\Windows\System32\calc.exe' \
                                    CommandLineArguments:'' \
                                    WorkingDirectory:'' \
                                    WindowStyle:System.ProcessWindowStyle.Normal \
                                    ProcessId=> ProcessId

UIAutomation.Click                  Element: Calc4.Calc4.CalcWindow.MenuBarView \
                                    ClickType:UIAutomation.ClickType.LeftClick \
                                    MousePositionRelativeToElement:UIAutomation.RectangleEdgePoint.MiddleCenter \
                                    OffsetX:0 \
                                    OffsetY:0

In Notepad I’ve been able to interact with the expanded menu, via an analogous selector and modifier keys, but so far not here.

Regards,
burque505

It has occurred to me that a missing DLL may be the culprit for not being able to access Menubar menu items (true so far for Calculator, Notepad, and Acrobat Pro XI). After reading this SO post I examined UiAutomationClientSideProviders.dll (there are numerous versions on my machine). The requisite information for accessing Menubar items appears to be there. UiAutomation clearly has the ability to access these selectors. Using Automation Spy (a very nice utility, although not without its foibles), I get the following selector for the Acrobat->File->Open control (it can take a number of tries to select):

$engine.GetTopLevel([NullString]::Value, "Adobe Acrobat Pro").MenuBar("Application").MenuItem("File").Menu("File").MenuItem("Open...")

This is analagous to this kludged, manually created selector:

kludge

But only the Menubar itself can be selected with UiSpy in its present incarnation; that is, the selector will read as

menubar[name="Application"]

on Win7, and will have an additional ‘id’ property on Win10.

Perhaps this will be useful, although I feel as if I’m grasping at straws.

Regards,
burque505