No project description provided
Project description
EasySelenium
Table of Contents
Overview
The EasySelenium project is designed to make the Selenium module a little bit easier to use. It supports automatic chromedriver updates, and shorter syntax for finding_elements.
Modules
The two main funtions of the module can be imported using
from seleniumeasy import WebDrvier
from seleniumeasy import update_driver
Configuration
To easily download all repo code onto your local machine download the selenium-easy module from pip
pip install seleniumeasy
Usage
WebDriver Class Usage
The WebDriver class is designed to simplify Selenium programming by reducing tedious syntax. Below are the usage instructions and examples.
Initialization
from seleniumeasy import WebDriver
# Initialize WebDriver with default settings
driver = WebDriver()
# Initialize WebDriver in headless mode
driver = WebDriver(headless=True)
# Initialize WebDriver with a custom memory structure
driver = WebDriver(memory_structure={})
#Initialize WebDriver, if unsuccesful try updating the chromedriver for windows and initialize again
driver = WebDriver(headless = True, platform = 'win64')
Parameters
headless: A boolean to determine whether the opened page will be visible. IfTrue, the browser will run in headless mode (no GUI). Defaults toFalse.memory_structure: A data structure to hold values for later use. Defaults to an empty list.CHROMEDRIVER_PATH: The path to yourchromedriver.exe, by default will assume the current working directory.
Methods
find_element_by_id
element = driver.find_element_by_id('element_id', wait=10, errors='raise')
id: The ID of the element to find.wait: Time in seconds to wait for the element to be present. Defaults toNone.errors: Error handling strategy. If'raise', an exception will be raised on error. If'coerce', the error will be printed and the program will continue.
find_elements_by_id
elements = driver.find_elements_by_id('element_id', wait=10, errors='raise')
id: The ID of the elements to find.wait: Time in seconds to wait for the elements to be present. Defaults toNone.errors: Error handling strategy. If'raise', an exception will be raised on error. If'coerce', the error will be printed and the program will continue.
EasySelenium can also be used to search by class, css selector, and by xpath with similar syntax, using:
find_element_by_classandfind_elements_by_classto search by classfind_element_by_cssandfind_elements_by_cssto search by css selectorfind_element_by_xpathandfind_elements_by_xpathto search by xpath
get_soup
#Returns a BeautifulSoup html parser of the JS-rendered page.
soup = driver.get_soup()
Example Usage
from seleniumeasy import WebDriver
with WebDriver(headless=True) as driver:
driver.get('https://example.com')
#This may not exist on the website, so in that case we'll just log that it wasn't found instead of halting the program
element = driver.find_element_by_id('example_id', wait=10, errors='raise')
print(element.text if element else "Element not found")
#This is essential for the program to run, raise an error if not found
elements = driver.find_elements_by_class('example_class', wait=10, errors='coerce')
for elem in elements:
print(elem.text)
#Create a BeautifulSoup parser of the driver (post JS-rendering)
soup = driver.get_soup()
Updating Chromedriver
The update_driver function allows you to automatically download the most recent version of the chromedriver for an input Operating System.
Platforms
The available platforms are:
linux64mac-arm64mac-x64win32win64
Example Usage
from seleniumeasy import update_driver
# Update chromedriver for Windows 64-bit
update_driver('win64')
# Update chromedriver for macOS ARM64
update_driver('mac-arm64')
This will download the most recent chromedriver for the specified platform to the current working directory. It is an intended future update to customize the driver download/launch locations for each project.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file seleniumeasy-0.1.1.tar.gz.
File metadata
- Download URL: seleniumeasy-0.1.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9aa967862ea5aaeffab34918e1d4c66ce37be27423d4ef2ba01bc57f68802ef2
|
|
| MD5 |
5c6a13dfabaafcdf3669037e8c575dee
|
|
| BLAKE2b-256 |
c4d49ff7b3fc68e4dd9e6c8221833ed017e39470e69d2431d206da7ee411f79d
|
File details
Details for the file seleniumeasy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: seleniumeasy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e7fa498dc1c19a7c3cc4265a03cdedfc1383220465aceb9d9051ffbaffd2994
|
|
| MD5 |
5b6bf4151b7f339d16649b7b835ded87
|
|
| BLAKE2b-256 |
fe321b97e8f043f19d4c8ad50c7f88971c98745289d4da6897073899c7ff6a3a
|