Class ElementHandle

Class Documentation

class ElementHandle

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

Public Functions

inline bool is_valid() const

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

inline std::optional<SharedString> id() const

Returns the element’s qualified id. Returns None if the element is not valid anymore or the element does not have an id. A qualified id consists of the name of the surrounding component as well as the provided local name, separate by a double colon.

 ,no-preview
component PushButton {
    /* .. *&zwj;/
}

export component App {
   mybutton := PushButton { } // known as `App::mybutton`
   PushButton { } // no id
}
inline std::optional<SharedString> type_name() const

Returns the element’s type name; std::nullopt if the element is not valid anymore.

 ,no-preview
component PushButton {
    /* .. *&zwj;/
}

export component App {
   mybutton := PushButton { } // type_name is "PushButton"
}

inline std::optional<SharedVector<SharedString>> bases() const

Returns the element’s base types as an iterator; None if the element is not valid anymore.

 ,no-preview
component ButtonBase {
    /* .. *&zwj;/
}

component PushButton inherits ButtonBase {
    /* .. *&zwj;/
}

export component App {
   mybutton := PushButton { } // bases will be ["ButtonBase"]
}
inline std::optional<slint::testing::AccessibleRole> accessible_role() const

Returns the value of the element’s accessible-role property, if present. Use this property to locate elements by their type/role, i.e. buttons, checkboxes, etc.

inline std::optional<SharedString> accessible_label() const

Returns the accessible-label of that element, if any.

inline std::optional<SharedString> accessible_value() const

Returns the accessible-value of that element, if any.

inline std::optional<SharedString> accessible_placeholder_text() const

Returns the accessible-placeholder-text of that element, if any.

inline std::optional<SharedString> accessible_description() const

Returns the accessible-description of that element, if any.

inline std::optional<float> accessible_value_maximum() const

Returns the accessible-value-maximum of that element, if any.

inline std::optional<float> accessible_value_minimum() const

Returns the accessible-value-minimum of that element, if any.

inline std::optional<float> accessible_value_step() const

Returns the accessible-value-step of that element, if any.

inline std::optional<bool> accessible_checked() const

Returns the accessible-checked of that element, if any.

inline std::optional<bool> accessible_checkable() const

Returns the accessible-checkable of that element, if any.

inline void set_accessible_value(SharedString value) const

Sets the accessible-value of that element.

Setting the value will invoke the accessible-action-set-value callback.

inline void invoke_accessible_increment_action() const

Invokes the increase accessibility action of that element (accessible-action-increment).

inline void invoke_accessible_decrement_action() const

Invokes the decrease accessibility action of that element (accessible-action-decrement).

inline void invoke_accessible_default_action() const

Invokes the default accessibility action of that element (accessible-action-default).

inline LogicalSize size() const

Returns the size of this element.

inline LogicalPosition absolute_position() const

Returns the absolute position of this element.

Public Static Functions

template<typename T, std::invocable<ElementHandle> Visitor, typename R = std::invoke_result_t<Visitor, ElementHandle>>
static inline auto visit_elements(const ComponentHandle<T> &component, Visitor visitor) -> std::invoke_result_t<Visitor, ElementHandle>

Visits visible elements within a component and call 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 convertts to true, then the function returns a default constructed value;

auto element = ElementHandle::visit_elements(component, [&](const ElementHandle& eh)
         -> std::optional<ElementHandle> {
     return eh.id() == "Foo::bar" ? std::make_optional(eh) : std::nullopt;
});
template<typename T>
static inline SharedVector<ElementHandle> find_by_accessible_label(const ComponentHandle<T> &component, std::string_view label)

Find all elements matching the given accessible label.

template<typename T>
static inline SharedVector<ElementHandle> find_by_element_id(const ComponentHandle<T> &component, std::string_view element_id)

Find all elements matching the given element_id.

template<typename T>
static inline SharedVector<ElementHandle> find_by_element_type_name(const ComponentHandle<T> &component, std::string_view type_name)

Find all elements matching the given type name.