Selenium-python but lighter: Helium is the best Python library for web automation.

Overview

Selenium-python but lighter: Helium

Selenium-python is great for web automation. Helium makes it easier to use. For example:

Helium Demo

Under the hood, Helium forwards each call to Selenium. The difference is that Helium's API is much more high-level. In Selenium, you need to use HTML IDs, XPaths and CSS selectors to identify web page elements. Helium on the other hand lets you refer to elements by user-visible labels. As a result, Helium scripts are typically 30-50% shorter than similar Selenium scripts. What's more, they are easier to read and more stable with respect to changes in the underlying web page.

Because Helium is simply a wrapper around Selenium, you can freely mix the two libraries. For example:

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

So in other words, you don't lose anything by using Helium over pure Selenium.

In addition to its more high-level API, Helium simplifies further tasks that are traditionally painful in Selenium:

  • Web driver management: Helium ships with its own copies of ChromeDriver and geckodriver so you don't need to download and put them on your PATH.
  • iFrames: Unlike Selenium, Helium lets you interact with elements inside nested iFrames, without having to first "switch to" the iFrame.
  • Window management. Helium notices when popups open or close and focuses / defocuses them like a user would. You can also easily switch to a window by (parts of) its title. No more having to iterate over Selenium window handles.
  • Implicit waits. By default, if you try click on an element with Selenium and that element is not yet present on the page, your script fails. Helium by default waits up to 10 seconds for the element to appear.
  • Explicit waits. Helium gives you a much nicer API for waiting for a condition on the web page to become true. For example: To wait for an element to appear in Selenium, you would write:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "myDynamicElement"))
    )
    With Helium, you can write:
    wait_until(Button('Download').exists)

Installation

To get started with Helium, you need Python 3 and Chrome or Firefox.

If you already know Python, then the following command should be all you need:

pip install helium

Otherwise - Hi! I would recommend you create a virtual environment in the current directory. Any libraries you download (such as Helium) will be placed there. Enter the following into a command prompt:

python3 -m venv venv

This creates a virtual environment in the venv directory. To activate it:

# On Mac/Linux:
source venv/bin/activate
# On Windows:
call venv\scripts\activate.bat

Then, install Helium using pip:

python -m pip install helium

Now enter python into the command prompt and (for instance) the commands in the animation at the top of this page (from helium import *, ...).

Your first script

I've compiled a cheatsheet that quickly teaches you all you need to know to be productive with Helium.

API Documentation

The documentation for this project can be found here.

Status of this project

I have too little spare time to maintain this project for free. If you'd like my help, please go to my web site to ask about my consulting rates. Otherwise, unless it is very easy for me, I will usually not respond to emails or issues on the issue tracker. I will however accept and merge PRs. So if you add some functionality to Helium that may be useful for others, do share it with us by creating a Pull Request. For instructions, please see Contributing below.

How you can help

I find Helium extremely useful in my own projects and feel it should be more widely known. Here's how you can help with this:

  • Star this project on GitHub.
  • Tell your friends and colleagues about it.
  • Share it on Twitter with one click
  • Share it on other social media
  • Write a blog post about Helium.

With this, I think we can eventually make Helium the de-facto standard for web automation in Python.

Contributing

Pull Requests are very welcome. Please follow the same coding conventions as the rest of the code, in particular the use of tabs over spaces. Also, read through my PR guidelines. Doing this will save you (and me) unnecessary effort.

Before you submit a PR, ensure that the tests still work:

pip install -Ur requirements/test.txt
python setup.py test

This runs the tests against Chrome. To run them against Firefox, set the environment variable TEST_BROWSER to firefox. Eg. on Mac/Linux:

TEST_BROWSER=firefox python setup.py test

On Windows:

set TEST_BROWSER=firefox
python setup.py test

If you do add new functionality, you should also add tests for it. Please see the tests/ directory for what this might look like.

History

I (Michael Herrmann) originally developed Helium in 2013 for a Polish IT startup called BugFree software. (It could be that you have seen Helium before at https://heliumhq.com.) We shut down the company at the end of 2019 and I felt it would be a shame if Helium simply disappeared from the face of the earth. So I invested some time to modernize it and bring it into a state suitable for open source.

Helium used to be available for both Java and Python. But I because I now only use it from Python, I didn't have time to bring the Java implementation up to speed as well. Similarly for Internet Explorer: Helium used to support it, but since I have no need for it, I removed the (probably broken) old implementation.

Comments
  • Change Chromedriver Path

    Change Chromedriver Path

    Hi, So i have a Script that uses Chromedriver and i want it to run on Heroku, but the problem is that you need to change the Chromedriver path to something like that: options.binary_location = os.environ.get("GOOGLE_CHROME_BIN") and the Start needs to look like that: (executable_path=os.environ.get("CHROMEDRIVER_PATH"),options=options) (Thats code from Selenium). Is there a way to do something like that? Thanks.

    opened by h4Ck3D001 14
  • Doesn't support the new Chrome 91 stable version

    Doesn't support the new Chrome 91 stable version

    Hi, Helium doesn't support the new chrome 91 only 89 and returns error saying that.

    Can you please show me how to update the chromedriver inside helium so it can support Chrome browser version 91 (stable, not beta or unstable). Without specifying the chrome driver too.

    Is there a way to change the chromedricer directly inside Helium's files, without adding anything to the code.

    Thank you

    opened by bradli99 12
  • Just Updated Chrome driver package to its latest version 89.0.4389.90

    Just Updated Chrome driver package to its latest version 89.0.4389.90

    Hello sir, pls kindly accept my pull request so that it will be easy to use for new folks like me and i have just changed the old driver from /selenium-python-helium/tree/master/helium/_impl/webdrivers to new driver and i have taken the package from https://chromedriver.storage.googleapis.com/index.html?path=89.0.4389.23/ so kindly make these changes sir

    opened by avinashtechlvr 10
  • Add documentation

    Add documentation

    Here's what I changed:

    • Change default documentation folder from doc/ to docs/. Update README accordingly.
    • Change default package configuration file from setup.py to pyproject.toml as according to pep517 (under review)
    • Add flake8 configuration to enable consistent code style among all contributors.

    Reference: #38

    opened by IgnisDa 9
  • Helium cannot launch chrome inside AWS lambda environment

    Helium cannot launch chrome inside AWS lambda environment

    Recently we moved our Selenium UI tests to AWS Lambda and for this we switched to a lighter version of headless chromium as the default chromium is not compatible with AWS lambda. Now we wanted to use Helium for our existing tests. Though we wanted to run our tests in headless chromium, we are getting "cannot Import name FirefoxOptions" exception when we tried running our tests with Helium inside AWS Lambda environment. Please find screenshot with logs for the same. Screenshot from 2020-06-24 19-45-07

    opened by sanjuktahazarika 7
  • Add proxy support to chrome webdriver

    Add proxy support to chrome webdriver

    This allows users to start a chrome webdriver that uses a proxy. The host and port should be passed to the function start_chrome_proxy as a string in the format "host:port". Tested and working on Windows/Linux. I had wanted to add support for firefox too but configuring a proxy with the geckodriver requires a bit more and looked like it would be different depending on the OS. i didn't want people to have to pass 3 or 4 more args to the method for that so I decided i'd wait on feedback before doing that.

    let me know what you think/if you think this is the proper way to add this functionality.

    opened by stone-wall 7
  • ingognito and window size setting

    ingognito and window size setting

    Is it possible to set chrome to use incognito mode, and also set the size of the window?

    I know selenium can do this, but didn't find how to 'map' those options to helium.

    opened by punasusi 7
  • Raspberry pi ?

    Raspberry pi ?

    Hey man !

    Nice job ! I was wondering if you support ARM devices like raspberry pi ? I gave a shot but I got a Exec format error, and I am assuming linux drivers are not compatible for ARM platform :)

    opened by vlidu 7
  • Code quality improvement

    Code quality improvement

    Hey @mherrmann, I am opening this PR to fix a few interesting code quality issues that were detected on static analysis of this repo. This analysis was performed with DeepSource, a code review automation tool that detects problems in contributions and helps developers automatically fix some of them.

    Changes

    • Removed methods with unnecessary super delegation.
    • Removed unused imports
    • Removed unnecessary generator
    • ~Used hypot method to calculate the hypotenuse~
    • ~Added .deepsource.toml config~
    opened by withshubh 6
  • Link is matching partial text

    Link is matching partial text

    I'm doing a simple click(Link("Algebra I", below="Biology")) to click dropdown links. There are two values in the dropdown that are similar.

    Algebra I Algebra I Elective

    It keeps clicking the one with "Elective" in the text which is only a partial match. This is not the expected behavior is it?

    How can I have it do a full text match and not partial? I've tried using xPath "//*/ul/li/a[text()='Algebra I']" but it seems to have difficulty finding this dropdown text for some reason.

    UPDATE: I found the following workaround. Not ideal but it works.

    links = find_all(S("//*/ul/li/a"))
        for link in links:
            if link.web_element.text == "Algebra I":
                # match found
                click(link.web_element)
                break
    
    opened by permster 5
  • Added get_attribute to elements with tests.

    Added get_attribute to elements with tests.

    Found myself wanting to test that an input had changed type on the page and thought it might be useful if we could access html attributes from elements. Tests passing (skipping some when using firefox driver).

    helium_pass

    opened by CraicOverflow89 4
  • Update to support Selenium 4 + up to Python v3.11

    Update to support Selenium 4 + up to Python v3.11

    -bump supported Python & selenium versions to work with newer python + selenium 4 -updated chromedriver to v107 and update geckodriver -removed Python3.5 (pretty old) -bump the module version

    opened by nchantarotwong 8
  • How to add Custom Headers to helium ?

    How to add Custom Headers to helium ?

    Hi so i have the followinng code, i can change the user-agent jsut fine, but how to add additional header options ?

    from selenium.webdriver import FirefoxOptions
    from helium import*
    
    
    useragent = "Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0"
    
    options = FirefoxOptions()
    
    options.set_preference("general.useragent.override",useragent)
    
    
    s = start_firefox("https://www.instagram.com", headless=False, options=options,)
    
    time.sleep(15)
    
    kill_browser()
    
    

    i want to add the following full headers.. How can I do that ? Thanks

    headers = {"Accept":	"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
    "Accept-Encoding"	: "gzip, deflate, br",
    "Accept-Language"	: "en-GB,en;q=0.5",
    "Connection"	: "keep-alive",
    "Host"	: "data.similarweb.com",
    "Sec-Fetch-Dest"	: "document",
    "Sec-Fetch-Mode"	: "navigate",
    "Sec-Fetch-Site"	: "none",
    "Sec-Fetch-User"	: "?1",
    "Upgrade-Insecure-Requests"	: "1",
    "User-Agent"	: "Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0"}
    
    opened by firaki12345-cmd 2
  • Support renamed Chrome.app on macOS

    Support renamed Chrome.app on macOS

    I got an error when launching helium via driver = start_chrome():

    selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
    

    After some trial and error I noticed Chrome gets installed into /Applications/Google Chrome.app by default, however I had renamed it to just Chrome.app, presumably breaking the binary lookup functionality of helium. It was easily fixed by linking Chrome to the expexted path via ln -s /Applications/Chrome.app /Applications/Google\ Chrome.app -however an API access à la driver = start_chrome(binary_path="/Applications/Chome.app") would be preferable.

    opened by finngaida 0
  • 👋 From the Selenium project!

    👋 From the Selenium project!

    At the Selenium Project we want to collaborate with you and work together to improve the WebDriver ecosystem. We would like to meet you, understand your pain points, and discuss ideas around Selenium and/or WebDriver.

    If you are interested, please fill out the form below and we will reach out to you. https://forms.gle/Z72BmP4FTsM1GKgE6

    We are looking forward to hearing from you!

    PS: Feel free to close this issue, it was just meant as a way to reach out to you 😄

    opened by diemol 0
Releases(v3.0.9)
Owner
Michael Herrmann
Michael Herrmann
PENBUD is penetration testing buddy which helps you in penetration testing by making various important tools interactive.

penbud - Penetration Tester Buddy PENBUD is penetration testing buddy which helps you in penetration testing by making various important tools interac

Himanshu Shukla 15 Feb 01, 2022
Load and performance benchmark tool

Yandex Tank Yandextank has been moved to Python 3. Latest stable release for Python 2 here. Yandex.Tank is an extensible open source load testing tool

Yandex 2.2k Jan 03, 2023
An AWS Pentesting tool that lets you use one-liner commands to backdoor an AWS account's resources with a rogue AWS account - or share the resources with the entire internet 😈

An AWS Pentesting tool that lets you use one-liner commands to backdoor an AWS account's resources with a rogue AWS account - or share the resources with the entire internet 😈

Brandon Galbraith 276 Mar 03, 2021
FauxFactory generates random data for your automated tests easily!

FauxFactory FauxFactory generates random data for your automated tests easily! There are times when you're writing tests for your application when you

Og Maciel 37 Sep 23, 2022
Flexible test automation for Python

Nox - Flexible test automation for Python nox is a command-line tool that automates testing in multiple Python environments, similar to tox. Unlike to

Stargirl Flowers 941 Jan 03, 2023
Simple assertion library for unit testing in python with a fluent API

assertpy Simple assertions library for unit testing in Python with a nice fluent API. Supports both Python 2 and 3. Usage Just import the assert_that

19 Sep 10, 2022
Parameterized testing with any Python test framework

Parameterized testing with any Python test framework Parameterized testing in Python sucks. parameterized fixes that. For everything. Parameterized te

David Wolever 714 Dec 21, 2022
A complete test automation tool

Golem - Test Automation Golem is a test framework and a complete tool for browser automation. Tests can be written with code in Python, codeless using

486 Dec 30, 2022
The evaluator covering all of the metrics required by tasks within the DUE Benchmark.

DUE Evaluator The repository contains the evaluator covering all of the metrics required by tasks within the DUE Benchmark, i.e., set-based F1 (for KI

DUE Benchmark 4 Jan 21, 2022
Ab testing - The using AB test to test of difference of conversion rate

Facebook recently introduced a new type of offer that is an alternative to the current type of bidding called maximum bidding he introduced average bidding.

5 Nov 21, 2022
Nokia SR OS automation

Nokia SR OS automation Nokia is one of the biggest vendors of the telecommunication equipment, which is very popular in the Service Provider segment.

Karneliuk.com 7 Jul 23, 2022
PyAutoEasy is a extension / wrapper around the famous PyAutoGUI, a cross-platform GUI automation tool to replace your boooring repetitive tasks.

PyAutoEasy PyAutoEasy is a extension / wrapper around the famous PyAutoGUI, a cross-platform GUI automation tool to replace your boooring repetitive t

Dingu Sagar 7 Oct 27, 2022
This is a Python script for Github Bot which uses Selenium to Automate things.

github-follow-unfollow-bot This is a Python script for Github Bot which uses Selenium to Automate things. Pre-requisites :- Python A Github Account Re

Chaudhary Hamdan 10 Jul 01, 2022
Selects tests affected by changed files. Continous test runner when used with pytest-watch.

This is a pytest plug-in which automatically selects and re-executes only tests affected by recent changes. How is this possible in dynamic language l

Tibor Arpas 614 Dec 30, 2022
Ward is a modern test framework for Python with a focus on productivity and readability.

Ward is a modern test framework for Python with a focus on productivity and readability.

Darren Burns 1k Dec 31, 2022
A collection of benchmarking tools.

Benchmark Utilities About A collection of benchmarking tools. PYPI Package Table of Contents Using the library Installing and using the library Manual

Kostas Georgiou 2 Jan 28, 2022
Plugin for generating HTML reports for pytest results

pytest-html pytest-html is a plugin for pytest that generates a HTML report for test results. Resources Documentation Release Notes Issue Tracker Code

pytest-dev 548 Dec 28, 2022
The Penetration Testers Framework (PTF) is a way for modular support for up-to-date tools.

The PenTesters Framework (PTF) is a Python script designed for Debian/Ubuntu/ArchLinux based distributions to create a similar and familiar distribution for Penetration Testing

trustedsec 4.5k Dec 28, 2022
HTTP traffic mocking and testing made easy in Python

pook Versatile, expressive and hackable utility library for HTTP traffic mocking and expectations made easy in Python. Heavily inspired by gock. To ge

Tom 305 Dec 23, 2022
Android automation project with pytest+appium

Android automation project with pytest+appium

1 Oct 28, 2021