Debug
Element dumps and XPath locators, ported from FlaUI.Core.Debug. The same calls are available
on every element as AutomationElement.details and
AutomationElement.get_xpath_to_element. See Utilities → Debugging elements
for a walkthrough.
flaui.core.debug
Python wrapper for FlaUI.Core.Debug: element dumps and XPath locators for debugging.
FlaUI.Core.Debug is a static C# helper class with two methods:
Debug.Details(element)returns a multi-line text dump of an element's identification properties, details, supported patterns and their values (and the same for its children).Debug.GetXPathToElement(element, rootElement)builds an XPath to the element from the desktop or from a given root.
Both are handy in failure messages and logs, and for turning an element you already found into a
locator you can paste back into :meth:~flaui.core.automation_elements.AutomationElement.find_first_by_x_path.
:class:~flaui.core.automation_elements.AutomationElement exposes the same calls as
:meth:~flaui.core.automation_elements.AutomationElement.details and
:meth:~flaui.core.automation_elements.AutomationElement.get_xpath_to_element.
details(element)
Return a multi-line text dump of an element's properties and supported patterns.
Wraps FlaUI.Core.Debug.Details. The text lists the identification properties (automation
id, control type, name, help text, bounding rectangle, class name, offscreen state, framework
id, process id) and the supported patterns, then the same block, indented, for each child.
Like FlaUI C#, it does not raise when a property cannot be read: it returns an empty string.
This happens intermittently on WinForms, whose MSAA proxy can reject the cached HelpText or
AutomationId of an element or child. FlaUI reports the error with Console.WriteLine,
which itself fails when the process has no console (as under pytest's output capture), so the
wrapper redirects the .NET console for the call and logs FlaUI's message as a warning on this
module's logger instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
ElementModel
|
The element to describe (any wrapped automation element). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The details text, one |
Source code in flaui/core/debug.py
get_xpath_to_element(element, root_element=None)
Return an XPath to element.
Wraps FlaUI.Core.Debug.GetXPathToElement. Each step is the element's control type, with a
one-based [n] index when its parent has several children of that type, for example
/Window[1]/Tab/TabItem[1]/RadioButton[1].
- Without
root_elementthe path starts at the desktop, so its first step is the top-level window. - With
root_elementthe walk stops at the root and leaves out the step for the root's direct child (this matches FlaUI C#). Passing the desktop therefore returns a path relative to the top-level window, ready forwindow.find_first_by_x_path(path).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
ElementModel
|
The element to build the path to. |
required |
root_element
|
Optional[ElementModel]
|
An ancestor to stop at; the desktop when omitted. An element that is not an ancestor makes the walk run past the desktop, which raises on UIA3. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The XPath; an empty string when |