# Helium

> Lighter browser automation for Python that targets elements by visible labels

- Category: Data & Labeling / Web Scraping & Crawling
- Language: Python
- Licence: MIT
- Repository: https://github.com/mherrmann/helium
- Canonical page: https://ai-tldr.dev/tools/helium/

## In short

Helium is a Python library for automating browsers such as Chrome and Firefox. Under the hood, it forwards each call to Selenium, but its API is much higher-level. It sits in the Web Scraping & Crawling category of the Data & Labeling tools and is open-source, written in Python and licensed MIT.

## Overview

Helium is a Python library for automating browsers such as Chrome and Firefox. Under the hood, it forwards each call to Selenium, but its API is much higher-level. Instead of identifying elements with HTML IDs, XPaths, or CSS selectors, you refer to them by the labels a real user would see on the page.

Because of this, Helium scripts are typically 30 to 50 percent shorter than equivalent Selenium scripts, and they tend to be easier to read and more stable when the underlying page changes. Since Helium is just a wrapper, you can freely mix it with plain Selenium calls, so you do not lose any of Selenium's power.

Helium also smooths over tasks that are painful in raw Selenium, including working with nested iFrames, managing popup windows, and waiting for elements. By default it waits up to 10 seconds for an element to appear before failing.

## What it does

- Refer to page elements by their user-visible labels instead of XPaths, IDs, or CSS selectors
- Interact with elements inside nested iFrames without first switching to the iFrame
- Automatic window management that focuses and defocuses popups the way a user would
- Built-in implicit waits (up to 10 seconds) so scripts do not fail on elements that load late
- A clean explicit-wait API, for example wait_until(Button('Download').exists)
- Drops down to plain Selenium at any time, since Helium is a thin wrapper around it

## Getting started

Helium needs Python 3 and either Chrome or Firefox installed. Create a virtual environment, install Helium with pip, then write a short script that starts a browser and interacts with a page using visible labels.

1. Create and activate a virtual environment

   A virtual environment installs Helium for just your current project rather than globally.

```bash
python3 -m venv venv
# On Mac/Linux:
source venv/bin/activate
# On Windows:
call venv\scripts\activate.bat
```

2. Install Helium with pip

   Install the library into your active environment using pip.

```bash
python -m pip install helium
```

3. Write your first script

   Import everything from helium, start a browser, and interact with the page using plain labels. This example searches Google and opens a result.

```python
from helium import *
start_chrome('google.com')
write('helium selenium github')
press(ENTER)
click('mherrmann/helium')
kill_browser()
```

4. Run headless when you no longer need the window

   Pass headless=True to start the browser without showing a window, which is handy once your script is ready to run unattended.

```python
start_chrome('google.com', headless=True)
```

## When to use it

- Automating repetitive web tasks such as logging in, filling forms, and clicking through pages
- Writing readable browser automation scripts that stay stable when page markup changes
- Scraping data from a site by reading element values by their visible labels
- Adding a friendlier high-level layer on top of existing Selenium-based automation
