Skip to main content

A Python wrapper for Selenium WebDriver with simplified API

Project description

SeleniumAuto

A Python wrapper for Selenium WebDriver with simplified API for browser automation.

Installation

pip install selenium_auto

Quick Start

from selenium_auto import SeleniumAuto

# Create instance
auto = SeleniumAuto()

# Start browser
driver = auto.get_driver()

# Navigate to webpage
auto.get("https://www.example.com")

# Get element
element = auto.get_element("//input[@id='username']")

# Input text
auto.send_keys("test_user", path="//input[@id='username']")

# Click element
auto.click(path="//button[@id='submit']")

# Close browser
auto.close()

Configure Chrome Driver Path

After first installation, you need to configure Chrome Driver path:

# Set Chrome Driver path
selenium_auto set_driver "C:\path\to\chromedriver.exe"

# Get current configured path
selenium_auto get_driver

# Check configuration status
selenium_auto check

Note: If path is not set on first use, a warning will be displayed and an error will be raised.

API Reference

Browser Driver

# Start Chrome (all parameters have default values)
driver = auto.get_driver(
    headless=False,           # Headless mode
    disable_gpu=True,         # Disable GPU
    disable_images=False,     # Disable images
    download_dir=None,       # Download directory
    proxy=None,              # Proxy address
    expire_minute=None,      # Driver expiration time (minutes)
    extension_path=None,     # Extension path
    chrome_driver_path=None  # Driver path (read from config)
)

# Start Edge
driver = auto.get_edge_driver(...)

# Close browser
auto.close(timeout=60)

Element Operations

# Get single element
element = auto.get_element("//xpath/path")
element = auto.get_element("//xpath/path", by='css')

# Get multiple elements
elements = auto.get_elements("//xpath/path")

# Input text
auto.send_keys("text", path="//input[@id='test']")
auto.send_keys("text", element=element, valid=False)

# Click
auto.click(path="//button[@id='submit']")
auto.click(element=element, check_path="//div[@id='result']")

# Clear input
auto.clear(path="//input[@id='test']")

Wait Conditions

# Wait for element to appear
auto.wait_element_appear("//div[@id='content']")

# Wait for element to disappear
auto.wait_element_disappear("//div[@id='loading']")

# Wait for element to be selected
auto.wait_is_selected("//input[@type='checkbox']")

# Wait for URL changes
auto.wait_url("https://example.com/page")
auto.wait_url_contains("/dashboard")
auto.wait_url_startswith("https://")
auto.wait_url_endswith(".html")

# Wait for window number
auto.wait_window_num(2)

# Wait for input value
auto.wait_value(element, "expected_value")

Window Operations

# Switch window
auto.switch_window(1)  # Switch to second window

# Keep one window, close others
auto.keep_one_window(0)  # Keep first window

XPath Query

# Get single result
result = auto.xpath_one("//title/text()")

# Get all results
results = auto.xpath_all("//div[@class='item']")

# Union results
text = auto.xpath_union("//div[@class='item']//text()", sep=', ')

Network Requests

# Navigate to URL
auto.get("https://example.com")
auto.get("https://example.com", check_netloc=True, check_path=True)

# Send async request (via browser)
result = auto.send_request(
    url="https://api.example.com/submit",
    method="POST",
    form_data={"key1": "value1", "key2": "value2"}
)

Print PDF

# Print current page to PDF
auto.download_print_pdf("output.pdf")
auto.download_print_pdf("output.pdf", width=8.27, height=11.69)  # A4
auto.download_print_pdf("output.pdf", print_background=True)

Other Utilities

# Check if driver is expired
if auto.is_expire():
    print("Driver expired")

# Select all matching elements
auto.select_all("//input[@type='checkbox']")

CLI Tools

After installation, you can use selenium_auto command directly:

# Set Chrome Driver path
selenium_auto set_driver "C:\chromedriver.exe"

# Get current path
selenium_auto get_driver

# Check configuration
selenium_auto check

Dependencies

  • selenium
  • lxml
  • psutil

License

MIT

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

selenium_auto-1.0.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

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

selenium_auto-1.0.1-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file selenium_auto-1.0.1.tar.gz.

File metadata

  • Download URL: selenium_auto-1.0.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.6

File hashes

Hashes for selenium_auto-1.0.1.tar.gz
Algorithm Hash digest
SHA256 aaefccb0235756a19e18114abe94e0e94ef5c87e466dbbe4fbc0cb685de3e1c0
MD5 904a677ed38be50a022c6f30ab1f2575
BLAKE2b-256 a7863a7a871d06a682333a7747cee158ab475965e31f35862cea4bc601c29501

See more details on using hashes here.

File details

Details for the file selenium_auto-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: selenium_auto-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.6

File hashes

Hashes for selenium_auto-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 068c2abbc3aa48524cc4f34487cfbecd8d0019343a220394af6f209b9574133e
MD5 ddfd582c0da735532a26edd6d16f1779
BLAKE2b-256 dfb15de1d7fca1305aa92ed0fc3797f43d9c0a9a71f1abf80f852f5500acadc5

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