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
Aioresponses is a helper for mock/fake web requests in python aiohttp package.

aioresponses Aioresponses is a helper to mock/fake web requests in python aiohttp package. For requests module there are a lot of packages that help u

402 Jan 06, 2023
A Library for Working with Sauce Labs

Robotframework - Sauce Labs Plugin This is a plugin for the SeleniumLibrary to help with using Sauce Labs. This library is a plugin extension of the S

joshin4colours 6 Oct 12, 2021
A small automated test structure using python to test *.cpp codes

Get Started Insert C++ Codes Add Test Code Run Test Samples Check Coverages Insert C++ Codes you can easily add c++ files in /inputs directory there i

Alireza Zahiri 2 Aug 03, 2022
A collection of testing examples using pytest and many other libreris

Effective testing with Python This project was created for PyConEs 2021 Check out the test samples at tests Check out the slides at slides (markdown o

Héctor Canto 10 Oct 23, 2022
MultiPy lets you conveniently keep track of your python scripts for personal use or showcase by loading and grouping them into categories. It allows you to either run each script individually or together with just one click.

MultiPy About MultiPy is a graphical user interface built using Dear PyGui Python GUI Framework that lets you conveniently keep track of your python s

56 Oct 29, 2022
Test for generating stylized circuit traces from images

I test of an image processing idea to take an image and make neat circuit board art automatically. Inspired by this twitter post by @JackRhysider

Miller Hooks 3 Dec 12, 2022
:game_die: Pytest plugin to randomly order tests and control random.seed

pytest-randomly Pytest plugin to randomly order tests and control random.seed. Features All of these features are on by default but can be disabled wi

pytest-dev 471 Dec 30, 2022
Percy visual testing for Python Selenium

percy-selenium-python Percy visual testing for Python Selenium. Installation npm install @percy/cli: $ npm install --save-dev @percy/cli pip install P

Percy 9 Mar 24, 2022
ApiPy was created for api testing with Python pytest framework which has also requests, assertpy and pytest-html-reporter libraries.

ApiPy was created for api testing with Python pytest framework which has also requests, assertpy and pytest-html-reporter libraries. With this f

Mustafa 1 Jul 11, 2022
Hamcrest matchers for Python

PyHamcrest Introduction PyHamcrest is a framework for writing matcher objects, allowing you to declaratively define "match" rules. There are a number

Hamcrest 684 Dec 29, 2022
HTTP client mocking tool for Python - inspired by Fakeweb for Ruby

HTTPretty 1.0.5 HTTP Client mocking tool for Python created by Gabriel Falcão . It provides a full fake TCP socket module. Inspired by FakeWeb Github

Gabriel Falcão 2k Jan 06, 2023
Minimal example of how to use pytest with automated 'devops' style automated test runs

Pytest python example with automated testing This is a minimal viable example of pytest with an automated run of tests for every push/merge into the m

Karma Computing 2 Jan 02, 2022
Python scripts for a generic performance testing infrastructure using Locust.

TODOs Reference to published paper or online version of it loadtest_plotter.py: Cleanup and reading data from files ARS_simulation.py: Cleanup, docume

Juri Tomak 3 Dec 15, 2022
Web testing library for Robot Framework

SeleniumLibrary Contents Introduction Keyword Documentation Installation Browser drivers Usage Extending SeleniumLibrary Community Versions History In

Robot Framework 1.2k Jan 03, 2023
This repository contnains sample problems with test cases using Cormen-Lib

Cormen Lib Sample Problems Description This repository contnains sample problems with test cases using Cormen-Lib. These problems were made for the pu

Cormen Lib 3 Jun 30, 2022
WrightEagle AutoTest (Has been updated by Cyrus team members)

Autotest2d WrightEagle AutoTest (Has been updated by Cyrus team members) Thanks go to WrightEagle Members. Steps 1- prepare start_team file. In this s

Cyrus Soccer Simulation 2D Team 3 Sep 01, 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
Pytest support for asyncio.

pytest-asyncio: pytest support for asyncio pytest-asyncio is an Apache2 licensed library, written in Python, for testing asyncio code with pytest. asy

pytest-dev 1.1k Jan 02, 2023
pytest plugin for testing mypy types, stubs, and plugins

pytest plugin for testing mypy types, stubs, and plugins Installation This package is available on PyPI pip install pytest-mypy-plugins and conda-forg

TypedDjango 74 Dec 31, 2022
Pytest-rich - Pytest + rich integration (proof of concept)

pytest-rich Leverage rich for richer test session output. This plugin is not pub

Bruno Oliveira 170 Dec 02, 2022