(MS) UIAutomation: clicking a menu


Task: open the Options window in the Services MMC snap-in.

Requirements: just do it. Optionally, if a handle of the child window is gotten, return it. Or an AutomaitonElement of the child window.

Solution: run the following code:

Get-UIAWindow -ProcessName mmc | `
 Get-UIAMenuItem -Name File | `
 Invoke-UIAMenuItemClick | `
 Get-UIAMenuItem -Name 'Options...' | `
 Invoke-UIAMenuItemClick;

The optional task #2 is accomplished by running this piece of code:

(Get-UIAWindow -ProcessName mmc | `
 Get-UIAMenuItem -Name File | `
 Invoke-UIAMenuItemClick | `
 Get-UIAMenuItem -Name 'Options...' | `
 Invoke-UIAMenuItemClick).Current

The optional task #1 can be done by running the following somewhat longer code:

(Get-UIAWindow -ProcessName mmc | `
Get-UIAMenuItem -Name File | `
Invoke-UIAMenuItemClick | `
Get-UIAMenuItem -Name 'Options...' | `
Invoke-UIAMenuItemClick).Current.NativeWindowHandle;

The secret is that the most cmdlets have its -PassThru parameter on ($true).

 

Advertisements

One response

  1. […] Software testing automation based mostly on PowerShell Software testing using Powershell Skip to content HomeAbout ← UIAutomation: clicking a menu […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: