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
Akulaku Create NewProduct Automation using Selenium Python

Akulaku-Create-NewProduct-Automation Akulaku Create NewProduct Automation using Selenium Python Usage: 1. Install Python 3.9 2. Open CMD on Bot Folde

Rahul Joshua Damanik 1 Nov 22, 2021
This file will contain a series of Python functions that use the Selenium library to search for elements in a web page while logging everything into a file

element_search with Selenium (Now With docstrings ?? ) Just to mention, I'm a beginner to all this, so it it's very possible to make some mistakes The

null 2 Aug 12, 2021
A folder automation made using Watch-dog, it only works in linux for now but I assume, it will be adaptable to mac and PC as well

folder-automation A folder automation made using Watch-dog, it only works in linux for now but I assume, it will be adaptable to mac and PC as well Th

Parag Jyoti Paul 31 May 28, 2021
A Python Selenium library inspired by the Testing Library

Selenium Testing Library Slenium Testing Library (STL) is a Python library for Selenium inspired by Testing-Library. Dependencies Python 3.6, 3.7, 3.8

Anลพe Peฤar 12 Dec 26, 2022
This is a web test framework based on python+selenium

Basic thoughts for this framework There should have a BasePage.py to be the parent page and all the page object should inherit this class BasePage.py

Cactus 2 Mar 9, 2022
A simple python script that uses selenium(chrome web driver),pyautogui,time and schedule modules to enter google meets automatically

A simple python script that uses selenium(chrome web driver),pyautogui,time and schedule modules to enter google meets automatically

null 3 Feb 7, 2022
0hh1 solver for the web (selenium) and also for mobile (adb)

0hh1 - Solver Aims to solve the '0hh1 puzzle' for all the sizes (4x4, 6x6, 8x8, 10x10 12x12). for both the web version (using selenium) and on android

Adwaith Rajesh 1 Nov 5, 2021
A web scraping using Selenium Webdriver

Savee - Images Downloader Project using Selenium Webdriver to download images from someone's profile on https:www.savee.it website. Usage The project

Caio Eduardo Lobo 1 Dec 17, 2021
A python bot using the Selenium library to auto-buy specified sneakers on the nike.com website.

Sneaker-Bot-UK A python bot using the Selenium library to auto-buy specified sneakers on the nike.com website. This bot is still in development and is

Daniel Hinds 4 Dec 14, 2022
A library to make concurrent selenium tests that automatically download and setup webdrivers

AutoParaSelenium A library to make parallel selenium tests that automatically download and setup webdrivers Usage Installation pip install autoparasel

Ronak Badhe 8 Mar 13, 2022
โœ… Python web automation and testing. ๐Ÿš€ Fast, easy, reliable. ๐Ÿ’ 

Build fast, reliable, end-to-end tests. SeleniumBase is a Python framework for web automation, end-to-end testing, and more. Tests are run with "pytes

SeleniumBase 3k Jan 4, 2023
A wrapper for webdriver that is a jumping off point for web automation.

Webdriver Automation Plus ===================================== Description: Tests the user can save messages then find them in search and Saved items

null 1 Nov 8, 2021
UUM Merit Form Filler is a web automation which helps automate entering a matric number to the UUM system in order for participants to obtain a merit

About UUM Merit Form Filler UUM Merit Form Filler is a web automation which helps automate entering a matric number to the UUM system in order for par

Ilham Rachmat 3 May 31, 2022
Python version of the Playwright testing and automation library.

?? Playwright for Python Docs | API Playwright is a Python library to automate Chromium, Firefox and WebKit browsers with a single API. Playwright del

Microsoft 7.8k Jan 2, 2023
Headless chrome/chromium automation library (unofficial port of puppeteer)

Pyppeteer Pyppeteer has moved to pyppeteer/pyppeteer Unofficial Python port of puppeteer JavaScript (headless) chrome/chromium browser automation libr

miyakogi 3.5k Dec 30, 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 1, 2022
Python package to easily work with selenium and manage tabs effectively.

Simple Selenium The aim of this package is to quickly get started with working with selenium for simple browser automation tasks. Installation Install

Vishal Kumar Mishra 1 Oct 27, 2021
This project is used to send a screenshot by email of your MyUMons schedule using Selenium python lib (headless mode)

MyUMonsSchedule Use MyUMonsSchedule python script to send a screenshot by email (Gmail) of your MyUMons schedule. If you use it on Windows, take care

Pierre-Louis D'Agostino 6 May 12, 2022
Fully functioning price detector built with selenium and python

Fully functioning price detector built with selenium and python

mark sikaundi 4 Mar 30, 2022