Skip to content

Element Cookbook

Control-by-control recipes against the bundled WPF test application. Each recipe shows the Python call next to the original FlaUI C# call. Pick a tab once and every recipe on the page switches with it.

Every Python snippet on this page runs

The Python tabs are included straight from examples/pytest/test_element_cookbook.py, one test per recipe, and the docs build fails if a referenced section disappears. Run them all:

uv run pytest examples/pytest/test_element_cookbook.py -v

All recipes assume a window (the main Window) and a condition factory cf. The pytest example shows how to get both. In C#, cf is the lambda parameter of FindFirstDescendant(cf => …).

Interactive controls

Button

button = window.find_first_descendant(cf.by_automation_id("InvokableButton")).as_button()
button.invoke()  # Invoke pattern: no mouse movement, works when the window is in the background
var button = window.FindFirstDescendant(cf => cf.ByAutomationId("InvokableButton")).AsButton();
button.Invoke(); // Invoke pattern: no mouse movement

CheckBox

checkbox = window.find_first_descendant(cf.by_name("Test Checkbox")).as_check_box()
checkbox.toggle()
state = checkbox.toggle_state  # ToggleState.On / Off / Indeterminate
var checkBox = window.FindFirstDescendant(cf => cf.ByName("Test Checkbox")).AsCheckBox();
checkBox.Toggle();
var state = checkBox.ToggleState; // ToggleState.On / Off / Indeterminate

RadioButton

radio = window.find_first_descendant(cf.by_automation_id("RadioButton1")).as_radio_button()
radio.is_checked = True
var radio = window.FindFirstDescendant(cf => cf.ByAutomationId("RadioButton1")).AsRadioButton();
radio.IsChecked = true;

ComboBox

combo = window.find_first_descendant(cf.by_automation_id("NonEditableCombo")).as_combo_box()
combo.select("Item 2")  # or combo.select(1)
selected = combo.selected_item.text
var combo = window.FindFirstDescendant(cf => cf.ByAutomationId("NonEditableCombo")).AsComboBox();
combo.Select("Item 2"); // or combo.Select(1)
var selected = combo.SelectedItem.Text;

TextBox

text_box = window.find_first_descendant(cf.by_automation_id("TextBox")).as_text_box()
text_box.text = "hello"  # Value pattern: sets the text directly
text_box.enter(" world")  # Keyboard: types into the focused box
var textBox = window.FindFirstDescendant(cf => cf.ByAutomationId("TextBox")).AsTextBox();
textBox.Text = "hello";  // Value pattern
textBox.Enter(" world"); // Keyboard

Slider

slider = window.find_first_descendant(cf.by_automation_id("Slider")).as_slider()
slider.value = 6
print(slider.minimum, slider.value, slider.maximum)
var slider = window.FindFirstDescendant(cf => cf.ByAutomationId("Slider")).AsSlider();
slider.Value = 6;
Console.WriteLine($"{slider.Minimum} {slider.Value} {slider.Maximum}");

Containers

ListBox

list_box = window.find_first_descendant(cf.by_automation_id("ListBox")).as_list_box()
item = list_box.select("ListBox Item #2")  # or list_box.select(1)
names = [i.text for i in list_box.items]
var listBox = window.FindFirstDescendant(cf => cf.ByAutomationId("ListBox")).AsListBox();
var item = listBox.Select("ListBox Item #2"); // or listBox.Select(1)
var names = listBox.Items.Select(i => i.Text).ToList();

Tree

The tree lives on the Complex Controls tab. The runnable test switches to that tab first.

tree = window.find_first_descendant(cf.by_automation_id("treeView1")).as_tree()
tree.items[0].expand()
tree.items[0].items[1].expand()
tree.items[0].items[1].items[0].select()
selected = tree.selected_tree_item.text
var tree = window.FindFirstDescendant(cf => cf.ByAutomationId("treeView1")).AsTree();
tree.Items[0].Expand();
tree.Items[0].Items[1].Expand();
tree.Items[0].Items[1].Items[0].Select();
var selected = tree.SelectedTreeItem.Text;

Grid

grid = window.find_first_descendant(cf.by_automation_id("listView1")).as_grid()
headers = [column.name for column in grid.header.columns]  # ["Key", "Value"]
first_row = [cell.value for cell in grid.rows[0].cells]  # ["1", "10"]
grid.select(1)
var grid = window.FindFirstDescendant(cf => cf.ByAutomationId("listView1")).AsGrid();
var headers = grid.Header.Columns.Select(c => c.Name).ToList(); // ["Key", "Value"]
var firstRow = grid.Rows[0].Cells.Select(c => c.Value).ToList(); // ["1", "10"]
grid.Select(1);

Tab

tab.select_tab_item(1, post_wait=True)  # "Complex Controls"
selected = tab.selected_tab_item.name
tab.SelectTabItem(1); // "Complex Controls"
var selected = tab.SelectedTabItem.Name;

Display

Label

label = window.find_first_descendant(cf.by_text("Test Label")).as_label()
text = label.text
var label = window.FindFirstDescendant(cf => cf.ByText("Test Label")).AsLabel();
var text = label.Text;

ProgressBar

bar = window.find_first_descendant(cf.by_automation_id("ProgressBar")).as_progress_bar()
progress = (bar.value - bar.minimum) / (bar.maximum - bar.minimum)
var bar = window.FindFirstDescendant(cf => cf.ByAutomationId("ProgressBar")).AsProgressBar();
var progress = (bar.Value - bar.Minimum) / (bar.Maximum - bar.Minimum);

Windows & dialogs

print(window.title)  # "FlaUI WPF Test App"
dialogs = window.modal_windows  # [] while no modal dialog is open
title_bar = window.title_bar  # .minimize_button / .maximize_button / .restore_button / .close_button
Console.WriteLine(window.Title);   // "FlaUI WPF Test App"
var dialogs = window.ModalWindows; // empty while no modal dialog is open
var titleBar = window.TitleBar;    // .MinimizeButton / .MaximizeButton / .RestoreButton / .CloseButton

Title bar buttons

FlaUI finds the title bar buttons by their AutomationIds. Standard Win32 and Store windows expose them; the WPF test app's title bar does not. The Calculator gallery script is an example where they work.