How to click invisible ListItem?

Oct 11, 2013 at 2:16 PM
If there are 10 ListItems in a List, and only 7 are visible, and the other 3 items need to scroll to see them.
The following code will case click on the outer of the List box. So how to click the 3 invisible items?
$_ | Invoke-UIAListItemClick | Invoke-UIAListItemClick
Coordinator
Oct 11, 2013 at 3:53 PM
HI VictorWoo,
UI Automation works with those items whose property Visible is True. If a control is just out of screen or in the background, UI Automation could work with it.

For example, a simple Windows Forms form with a ListBox and ten items inside (the most of them are out of the list box border):
$list = Get-UIAWindow -Name listItemOutOfScreen | Get-UIAList;

# the state of items:
$list | Get-UIAListItem | Get-UIAListItemSelectionItemState;

# selecting item one by one (by default, a list box is single-valued)
$list | Get-UIAListItem | Invoke-UIAListItemSelectItem;

# checking the state of items:
$list | Get-UIAListItem | Get-UIAListItemSelectionItemState;
# (in my case, only the tenth is selected)
I need to mention that while UI Automation works with controls that are not shown to the user, Win32 often doesn't.
Cmdlets with 'Control' in the name (Invoke-UIAControlClick, for example) won't work with such controls.

There is another pitfall: if a control doesn't support a pattern (pattern is a typical set of properties and methods the control could but not obliged to support), in several cmdlets are used Win32 clicks. For example, Invoke-UIA[Button,ListItem,etc]Click cmdlets use InvokePattern. If pattern fails or there is none, they use a Win32 click.
I mean, in such cases (mostly related to third-party or old controls), there is a cane for controls displayed and no cane for controls that are not shown to the user.

However, there is ScrollItemPattern:
# if we have name of the list item:
$list | Get-UIAListItem -n *010* | Invoke-UIAListItemScrollItem;

# if we don't have name:
($list | Get-UIAListItem)[9] | Invoke-UIAListItemScrollItem;
Finally, if list items are not of a usable type (i.e., they don't support patterns we used above), there is ScrollPattern for a container control (our list box):
$list | Invoke-UIAListScroll -VerticalPercent 100 -HorizontalPercent 0;
Marked as answer by VictorWoo on 10/11/2013 at 11:36 PM