Helium Python Library

repository·master·Indexed 27 days ago

https://github.com/mherrmann/helium

A high-level Python library for web automation that wraps Selenium. Helium allows developers to interact with web elements using user-visible labels instead of complex HTML selectors like XPaths or CSS selectors. It provides a simplified API for browser interaction, explicit waits via wait_until(), and the ability to mix Helium functions with standard Selenium API calls.

Tokens
1.8K
Snippets
11
Records
22
Agent score
94%

What's inside Helium

  1. Overview of Helium for web automation

    master
    Helium is a Python library designed for lighter web automation. It acts as a high-level wrapper around Selenium-python, providing a simpler and more intuitive API for automating websites while leveraging the underlying power of Selenium.
  2. Install Helium

    master

    To use Helium, you need Python 3 and either Chrome or Firefox installed. It is recommended to use a virtual environment to manage dependencies.

    1. Create and activate a virtual environment:

      • Mac/Linux:
        python3 -m venv venv
        source venv/bin/activate
      • Windows:
        python3 -m venv venv
        call venv\scripts\activate.bat
    2. Install Helium using pip:

      python -m pip install helium
    python -m pip install helium
  3. Build the documentation locally

    master

    To build the Helium documentation locally, ensure you have python and pip installed. Run the following commands from the project root to install the necessary development dependencies and generate the HTML documentation.

    The resulting documentation will be located in the docs/_build/ directory. You can view it by opening docs/_build/index.html in your web browser.

    pip install -Ur requirements/docs.txt
    make -C docs/ html
  4. Set up a Python virtual environment for Helium

    master

    It is recommended to use a virtual environment to keep your Helium installation isolated. Follow these steps:

    1. Create the virtual environment:

      python3 -m venv venv
    2. Activate the environment:

      • On Mac/Linux (bash shell):
        source venv/bin/activate
      • On Windows:
        call venv\Scripts\activate.bat
    3. Install Helium inside the activated environment:

      python -m pip install helium
    python3 -m venv venv
    # On Mac/Linux:
    source venv/bin/activate
    # On Windows:
    call venv\Scripts\activate.bat
    python -m pip install helium
  5. Basic web interaction workflow

    master

    A typical Helium script involves starting a browser, navigating to a URL, typing text, clicking elements, and closing the browser.

    from helium import *
    start_chrome('google.com')
    write('helium selenium github')
    press(ENTER)
    click('mherrmann/helium')
    go_to('github.com/login')
    write('username', into='Username')
    write('password', into='Password')
    click('Sign in')
    kill_browser()
  6. Mix Helium and Selenium APIs

    master

    Helium is a high-level wrapper around Selenium. Because it forwards calls to Selenium, you can freely mix Helium functions with standard Selenium API calls using the driver instance returned by Helium functions like start_chrome() or start_firefox().

    # A Helium function:
    driver = start_chrome()
    # A Selenium API:
    driver.execute_script("alert('Hi!');")
  7. Combine Helium and Selenium APIs

    master
    Helium is built on top of Selenium. You can access the underlying Selenium WebDriver using get_driver() or set a custom one with set_driver(). To convert a Helium element into a Selenium WebElement, use its .web_element property.
  8. Start a browser (Chrome or Firefox)

    master

    You can launch Chrome or Firefox using start_chrome() or start_firefox(). You can optionally pass a URL as the first argument to open immediately. To run the browser without a visible window (useful for automated tasks), set headless=True.

    start_chrome('google.com')
    start_chrome(headless=True)
    start_firefox('google.com', headless=True)