Skip to content

Search.Any

David O'Donoghue edited this page Jan 28, 2026 · 2 revisions

Search.Any

Find elements by matching against name, text, sprite, or path simultaneously.

Syntax

using static ODDGames.UIAutomation.ActionExecutor;

Search.Any(string pattern)

// Or using the static helper from ActionExecutor:
Any(string pattern)

Parameters

Parameter Type Description
pattern string Pattern to match (supports * wildcards and `

What It Matches

Any searches across multiple element properties:

Property Description
GameObject name The name in the hierarchy
Text content TMP_Text or Text component content
Sprite name Image component sprite name
Hierarchy path Full path like "Canvas/Panel/Button"

If the pattern matches any of these, the element is included.

Examples

Basic Usage

// Find anything containing "Settings"
await Click(Any("*Settings*"));
// Matches: GameObject named "SettingsButton", text "Settings", sprite "settings_icon", path "Menu/Settings"

// Find anything with "play"
await Click(Any("*play*"));
// Matches: "PlayButton", "Play", "play_icon", "MainMenu/Play"

Wildcards

// Find anything starting with "btn_"
await Click(Any("btn_*"));

// Find anything ending with "Panel"
await Wait(Any("*Panel"));

// Find anything containing "user"
await Click(Any("*user*"));

OR Patterns

// Find settings by any common identifier
await Click(Any("*settings*|*options*|*preferences*"));

// Find close/cancel actions
await Click(Any("*close*|*cancel*|*back*|X"));

When to Use Any

Scenario Recommendation
Not sure how element is identified Use Any()
Element has consistent naming Use Name()
Element has visible text Use Text()
Element has distinctive icon Use Sprite()
Need precise matching Use specific method

Any is useful for:

  • Exploratory testing when you don't know the exact identifiers
  • Flexible matching across different UI implementations
  • Finding elements that might be named differently across scenes

Chaining

Combine with other conditions for more precise matching:

// Find anything "settings" that's a button
await Click(Any("*settings*").Type<Button>());

// Find anything "close" in the top-right
await Click(Any("*close*|X").InRegion(ScreenRegion.TopRight));

// Find anything "submit" that's interactable
await Click(Any("*submit*").Interactable().First());

Performance Consideration

Any searches more properties than specific methods, so it may be slightly slower. For performance-critical tests or when you know the exact identifier type, prefer:

// More efficient if you know it's a text element
await Click(Text("Settings"));

// More efficient if you know it's named
await Click(Name("SettingsButton"));

Use Cases

Finding Common UI Patterns

// Find any confirmation button
await Click(Any("*ok*|*confirm*|*yes*|*accept*|*submit*"));

// Find any navigation element
await Click(Any("*back*|*home*|*menu*|*nav*"));

// Find any error/warning indicator
await Wait(Any("*error*|*warning*|*alert*"));

Flexible Test Scripts

// Works whether it's a "SettingsButton", "Settings" text, or "settings" sprite
await Click(Any("*settings*").First());

// Works across different UI implementations
await Click(Any("*play*|*start*|*begin*").First());

Debugging/Exploration

// Find all elements related to "user"
var userElements = await FindAll<RectTransform>(Any("*user*"));
foreach (var el in userElements)
{
    Debug.Log($"Found: {el.name}");
}

Related Pages

Clone this wiki locally