Skip to main content

A utility library for Selenium WebDriver to enable human-like interactions, robust exception handling, and web automation tasks like popup handling and URL normalization.

Project description

Selmate

Selmate is a Python utility library designed to enhance Selenium WebDriver automation by providing human-like interactions, robust exception handling, and utilities for common web automation tasks. It simplifies interactions with web elements, handles popups, normalizes URLs, and simulates natural user behavior like mouse movements and scrolling.

Features

  • Safe Element Interactions: Wrappers for Selenium operations (clicks, scrolls, etc.) with built-in exception handling for stale elements, timeouts, and more.
  • Human-Like Behavior: Simulates realistic mouse movements, scrolling, and latency to mimic human interactions.
  • Popup Handling: Automatically detects and handles popup banners, including those within iframes, with options to accept or close them.
  • URL Normalization: Utilities to normalize URLs relative to a base URL, with configurable handling of query strings, fragments, and parameters.
  • JavaScript Integration: Execute JavaScript for advanced interactions like smooth scrolling, element removal, and visibility checks.
  • Text Similarity: Identify confirmation buttons or close buttons using fuzzy text matching.

Installation

Install Selmate via pip:

pip install selmate

Usage

Here are some examples of using Selmate's core functionalities:

Example 1: Safe Element Click

from selenium import webdriver
from selmate.composites import complex_click
from selmate.selenium_primitives import find_element_safely
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://example.com")

# Safely find and click a button
button = find_element_safely(By.ID, "submit-button", driver)
if button and complex_click(button, driver):
    print("Button clicked successfully")

driver.quit()

Example 2: Handling Popup Banners

from selenium import webdriver
from selmate.composites import bypass_popup_banners

driver = webdriver.Chrome()
driver.get("https://example.com")

# Automatically handle popup banners
bypass_popup_banners(driver, observation_capacity=50, success_capacity=3, try_close=True)
print("Popups handled")

driver.quit()

Example 3: Human-Like Mouse Movement

from selenium import webdriver
from selmate.composites import wander_between_2_elements
from selmate.selenium_primitives import find_element_safely
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://example.com")

# Find two elements and simulate mouse movement between them
element1 = find_element_safely(By.ID, "element1", driver)
element2 = find_element_safely(By.ID, "element2", driver)
if element1 and element2:
    wander_between_2_elements(element1, element2, driver)

driver.quit()

License

Selmate is licensed under the MIT License. See the LICENSE file for details.

Contact

For questions or support, open an issue or contact the maintainer at waxbid@gmail.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selmate-1.0.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

selmate-1.0.2-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file selmate-1.0.2.tar.gz.

File metadata

  • Download URL: selmate-1.0.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.11 Windows/10

File hashes

Hashes for selmate-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b26b7d2b3fdf5c37eda936e610685ef4834d23c9a5b5900e5241cff7362a887c
MD5 9c764ee38599e1533e22fd5218ef699c
BLAKE2b-256 45beb07aaf41c779546ccb973b016d4f3d7f7c6ad985b436ae9867c581fe9568

See more details on using hashes here.

File details

Details for the file selmate-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: selmate-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.11 Windows/10

File hashes

Hashes for selmate-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 65b3b5d938b5cd1dc7dea8941c9ccd9ab6918d5c05753119523f9aba5457a6b2
MD5 d114e9d16a8a01b4850c93ce6957d14e
BLAKE2b-256 173bc74a31620b8d6a7654bc9b3b25a480b79878fc80b9d0c99a21f798fe65c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page