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
Local continuous test runner with pytest and watchdog.

pytest-watch -- Continuous pytest runner pytest-watch a zero-config CLI tool that runs pytest, and re-runs it when a file in your project changes. It

Joe Esposito 675 Dec 23, 2022
show python coverage information directly in emacs

show python coverage information directly in emacs

wouter bolsterlee 30 Oct 26, 2022
Automatic SQL injection and database takeover tool

sqlmap sqlmap is an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of

sqlmapproject 25.7k Jan 04, 2023
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
pytest plugin that let you automate actions and assertions with test metrics reporting executing plain YAML files

pytest-play pytest-play is a codeless, generic, pluggable and extensible automation tool, not necessarily test automation only, based on the fantastic

pytest-dev 67 Dec 01, 2022
Based on the selenium automatic test framework of python, the program crawls the score information of the educational administration system of a unive

whpu_spider 该程序基于python的selenium自动化测试框架,对某高校的教务系统的成绩信息实时爬取,在检测到成绩更新之后,会通过电子邮件的方式,将更新的成绩以文本的方式发送给用户,可以使得用户在不必手动登录教务系统网站时,实时获取成绩更新的信息。 该程序仅供学习交流,不可用于恶意攻

1 Dec 30, 2021
A Proof of concept of a modern python CLI with click, pydantic, rich and anyio

httpcli This project is a proof of concept of a modern python networking cli which can be simple and easy to maintain using some of the best packages

Kevin Tewouda 17 Nov 15, 2022
py.test fixture for benchmarking code

Overview docs tests package A pytest fixture for benchmarking code. It will group the tests into rounds that are calibrated to the chosen timer. See c

Ionel Cristian Mărieș 1k Jan 03, 2023
Python Projects - Few Python projects with Testing using Pytest

Python_Projects Few Python projects : Fast_API_Docker_PyTest- Just a simple auto

Tal Mogendorff 1 Jan 22, 2022
A testing system for catching visual regressions in Web applications.

Huxley Watches you browse, takes screenshots, tells you when they change Huxley is a test-like system for catching visual regressions in Web applicati

Facebook Archive 4.1k Nov 30, 2022
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
Front End Test Automation with Pytest Framework

Front End Test Automation Framework with Pytest Installation and running instructions: 1. To install the framework on your local machine: clone the re

Sergey Kolokolov 2 Jun 17, 2022
Test python asyncio-based code with ease.

aiounittest Info The aiounittest is a helper library to ease of your pain (and boilerplate), when writing a test of the asynchronous code (asyncio). Y

Krzysztof Warunek 55 Oct 30, 2022
Fail tests that take too long to run

GitHub | PyPI | Issues pytest-fail-slow is a pytest plugin for making tests fail that take too long to run. It adds a --fail-slow DURATION command-lin

John T. Wodder II 4 Nov 27, 2022
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
A pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database

This is a pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database. It allows you to specify fixtures for PostgreSQL process and client.

Clearcode 252 Dec 21, 2022
Automated Security Testing For REST API's

Astra REST API penetration testing is complex due to continuous changes in existing APIs and newly added APIs. Astra can be used by security engineers

Flipkart Incubator 2.1k Dec 31, 2022
A toolbar overlay for debugging Flask applications

Flask Debug-toolbar This is a port of the excellent django-debug-toolbar for Flask applications. Installation Installing is simple with pip: $ pip ins

863 Dec 29, 2022
d4rk Ghost is all in one hacking framework For red team Pentesting

d4rk ghost is all in one Hacking framework For red team Pentesting it contains all modules , information_gathering exploitation + vulnerability scanning + ddos attacks with 12 methods + proxy scraper

d4rk sh4d0w 15 Dec 15, 2022
Python Moonlight (Machine Learning) Practice

PyML Python Moonlight (Machine Learning) Practice Contents Design Documentation Prerequisites Checklist Dev Setup Testing Run Prerequisites Python 3 P

Dockerian Seattle 2 Dec 25, 2022