Skip to main content

Get Related Desktop Elements

Command description

Get the parent, child, sibling, or descendant of the specified desktop element. An element has at most one parent, but it may have multiple children or siblings. If multiple descendants match, the command reports an error; refine the captured element so that it always identifies a unique target. Select Descendant Element and specify an index to retrieve the nth matching descendant of the target element.

Command Input Parameters

input parametersInput parameter typeDescription
Desktop ElementWinElement or str (captured element UID, not element name, not ms-rpa-id)Source element. Select a captured element or use Get Desktop Element, Get Similar Desktop Elements, or Get Related Desktop Elements
RelationshipenumParent Element, Child Element, Sibling Element, Descendant Element
Descendant ElementsstrUID of the captured descendant descriptor, not its name or ms-rpa-id. Required only when Relationship is Descendant Element; the search starts from Desktop Element
Element Wait DurationnumberMaximum time to wait for the related element, in seconds. On timeout, the command reports an error or returns an empty list, depending on the relationship

Command Output Parameters

Output parametersOutput parameter typeDescription
Desktop ElementWinElement or list[WinElement]WinElement for Parent Element or Descendant Element; list[WinElement] for Child Element or Sibling Element

Type definition reference

tip

Applicable scenarios

  • Locate a target relative to an element that is easier to identify.
  • For example, after locating a product name in a list, retrieve the related price element.

Example

Get the group name in WeChat chat history

WeChat chat history is a list containing multiple direct child items. Each item represents a group or contact and contains its name.

Process

  1. Get the list element.
  2. Get all direct Item children of the list.
  3. Get the matching descendant of each item.
  • list elements

  • Descendants elements

    Because the search starts at Item, do not include ListItemControl or any ancestor nodes in the descendant descriptor.