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
Just a small test with lists in cython

Test for lists in cython Algorithm create a list of 10^4 lists each with 10^4 floats values (namely: 0.1) - 2 nested for iterate each list and compute

Federico Simonetta 32 Jul 23, 2022
a wrapper around pytest for executing tests to look for test flakiness and runtime regression

bubblewrap a wrapper around pytest for assessing flakiness and runtime regressions a cs implementations practice project How to Run: First, install de

Anna Nagy 1 Aug 05, 2021
Generic automation framework for acceptance testing and RPA

Robot Framework Introduction Installation Example Usage Documentation Support and contact Contributing License Introduction Robot Framework is a gener

Robot Framework 7.7k Jan 07, 2023
bulk upload files to libgen.lc (Selenium script)

LibgenBulkUpload bulk upload files to http://libgen.lc/librarian.php (Selenium script) Usage ./upload.py to_upload uploaded rejects So title and autho

8 Jul 07, 2022
Let your Python tests travel through time

FreezeGun: Let your Python tests travel through time FreezeGun is a library that allows your Python tests to travel through time by mocking the dateti

Steve Pulec 3.5k Dec 29, 2022
Photostudio是一款能进行自动化检测网页存活并实时给网页拍照的工具,通过调用Fofa/Zoomeye/360qua/shodan等 Api快速准确查询资产并进行网页截图,从而实施进一步的信息筛查。

Photostudio-红队快速爬取网页快照工具 一、简介: 正如其名:这是一款能进行自动化检测,实时给网页拍照的工具 信息收集要求所收集到的信息要真实可靠。 当然,这个原则是信息收集工作的最基本的要求。为达到这样的要求,信息收集者就必须对收集到的信息反复核实,不断检验,力求把误差减少到最低限度。我

s7ck Team 41 Dec 11, 2022
Repository for JIDA SNP Browser Web Application: Local Deployment

JIDA JIDA is a web application that retrieves SNP information for a genomic region of interest in Homo sapiens and calculates specific summary statist

3 Mar 03, 2022
Browser reload with uvicorn

uvicorn-browser This project is inspired by autoreload. Installation pip install uvicorn-browser Usage Run uvicorn-browser --help to see all options.

Marcelo Trylesinski 64 Dec 17, 2022
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
masscan + nmap 快速端口存活检测和服务识别

masnmap masscan + nmap 快速端口存活检测和服务识别。 思路很简单,将masscan在端口探测的高速和nmap服务探测的准确性结合起来,达到一种相对比较理想的效果。 先使用masscan以较高速率对ip存活端口进行探测,再以多进程的方式,使用nmap对开放的端口进行服务探测。 安

starnightcyber 75 Dec 19, 2022
🎓 Stepik Academy Автоматизация тестирования на Python

🎓 Stepik Academy Автоматизация тестирования на Python Запуск тестов выполняется в командной строке: pytest -v --tb=line --language=en --alluredir=all

Sergey 1 Dec 03, 2021
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
Free cleverbot without headless browser

Cleverbot Scraper Simple free cleverbot library that doesn't require running a heavy ram wasting headless web browser to actually chat with the bot, a

Matheus Fillipe 3 Sep 25, 2022
The best, free, all in one, multichecking, pentesting utility

The best, free, all in one, multichecking, pentesting utility

Mickey 58 Jan 03, 2023
Just for testing video streaming using pytgcalls.

tgvc-video-tests Just for testing video streaming using pytgcalls. Note: The features used in this repository is highly experimental and you might not

wrench 34 Dec 27, 2022
Tattoo - System for automating the Gentoo arch testing process

Naming origin Well, naming things is very hard. Thankfully we have an excellent

Arthur Zamarin 4 Nov 07, 2022
Django-google-optimize is a Django application designed to make running server side Google Optimize A/B tests easy.

Django-google-optimize Django-google-optimize is a Django application designed to make running Google Optimize A/B tests easy. Here is a tutorial on t

Adin Hodovic 39 Oct 25, 2022
BDD library for the py.test runner

BDD library for the py.test runner pytest-bdd implements a subset of the Gherkin language to enable automating project requirements testing and to fac

pytest-dev 1.1k Jan 09, 2023
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. An example o

pytest-dev 9.6k Jan 02, 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