$ show mherrmann/helium
Helium is a Python library that provides a higher-level, more intuitive API for browser automation, built on top of Selenium. It simplifies common web automation tasks such as clicking buttons, filling forms, handling alerts, switching windows, and dragging elements by allowing developers to reference page elements by their visible labels rather than low-level CSS selectors or XPath expressions. Under the hood, Helium translates each high-level command into Selenium calls, managing implicit waits, iframe traversal, and window focus automatically. The library is designed for both interactive use (e.g., testing) and scripting (e.g., web scraping), and it seamlessly integrates with raw Selenium for advanced use cases. The architecture follows a layered pattern: a public API module (`helium/__init__.py`) exposes functions and GUI element classes; an implementation layer (`helium/_impl/__init__.py`) contains the core logic including element location via XPath construction, frame iteration, and error handling; and utility modules provide geometry, string, and system helpers. The codebase is well-organized with clear separation between API and implementation, though the main implementation file is large and tightly coupled. The library is actively used (over 8,300 stars) and though maintenance is low-effort, it remains functional with recent Selenium compatibility.
The LLM identified 4 files worth highlighting for reuse:
Implements Rectangle and Point classes with comprehensive spatial operations including intersection, containment, directional relationship (is_to_left_of, is_above, etc.), distance calculation, and clipping. The Rectangle class handles coordinate systems elegantly and is completely self-contained (only importing math and namedtuple). This module could be extracted and reused in any project requiring 2D geometry computations, such as UI testing frameworks, game development, or layout engines.
Provides helper functions for constructing XPath predicates: `lower()` for case-insensitive matching, `replace_nbsp()` for non-breaking space handling, `predicate()` and `predicate_or()` for building XPath conditions. These functions are small, focused, and purely string-based, making them safe to extract for any project that needs to generate dynamic XPath queries. The code demonstrates careful handling of character encoding and predicate logic.
Contains `strip_tags()` (using Python's HTMLParser) and `get_easily_readable_snippet()` which produces a compact representation of HTML elements, e.g., `<button>...</button>` for nested content. The snippet function intelligently truncates long inner content while preserving the opening and closing tags. This is useful for debugging, logging, or generating human-readable descriptions from HTML source, and is isolated enough to be reused in any Python project.
Defines a `MatchType` interface and the `PREFIX_IGNORE_CASE` implementation that performs case-insensitive prefix matching with special handling for asterisks (often used for required fields) and non-breaking spaces. It generates both XPath expressions and Python string comparisons from the same logic. This module is self-contained and demonstrates non-trivial string manipulation for matching user-provided text against web content, and could be reused as a custom matching strategy in other text-matching contexts.