---
title: "slint::testing::ElementHandle Class"
description: "A handle to an element for querying accessible properties, intended for testing purposes."
---
```cpp
class ElementHandle;
```

```cpp
#include <slint-testing.h>
```

A handle to an element for querying accessible properties, intended for testing purposes.

## Public Static Functions

### `visit_elements`

```cpp
static std::invoke_result_t<Visitor, ElementHandle> slint::testing::ElementHandle::visit_elements(const ComponentHandle<T> &component, Visitor visitor)
```

Visits visible elements within a component and calls the visitor for each of them.

The visitor must be a callable object that accepts an `ElementHandle` and returns either `void`, or a type that can be converted to `bool`.

- If the visitor returns `void`, the visitation continues until all elements have been visited.
- If the visitor returns a type that can be converted to `bool`, the visitation continues as long as the conversion result is false; otherwise, it stops, returning that value. If the visitor never returns something that converts to true, then the function returns a default constructed value;

```cpp
auto element = ElementHandle::visit_elements(component, [&](const ElementHandle& eh)
         -> std::optional<ElementHandle> {
     return eh.id() == "Foo::bar" ? std::make_optional(eh) : std::nullopt;
});
```

### `find_by_accessible_label`

```cpp
static SharedVector<ElementHandle> slint::testing::ElementHandle::find_by_accessible_label(const ComponentHandle<T> &component, std::string_view label)
```

Find all elements matching the given accessible label.

### `find_by_element_id`

```cpp
static SharedVector<ElementHandle> slint::testing::ElementHandle::find_by_element_id(const ComponentHandle<T> &component, std::string_view element_id)
```

Find all elements matching the given element\_id.

### `find_by_element_type_name`

```cpp
static SharedVector<ElementHandle> slint::testing::ElementHandle::find_by_element_type_name(const ComponentHandle<T> &component, std::string_view type_name)
```

Find all elements matching the given type name.

## Public Functions

### `is_valid`

```cpp
bool slint::testing::ElementHandle::is_valid() const
```

Returns true if the underlying element still exists; false otherwise.