Skip to main content

A Python wrapper for Selenium WebDriver with simplified API

Project description

DecBrowser

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

Installation

pip install dec_browser

Quick Start

from dec_browser import DecBrowser

# Create instance
auto = DecBrowser()

# 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
dec_browser set_driver "C:\path\to\chromedriver.exe"

# Get current configured path
dec_browser get_driver

# Check configuration status
dec_browser 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 dec_browser command directly:

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

# Get current path
dec_browser get_driver

# Check configuration
dec_browser 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

dec_browser-1.0.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

dec_browser-1.0.1-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dec_browser-1.0.1.tar.gz
Algorithm Hash digest
SHA256 68489dd3a1eccdff3316a101150e6833c8da971271e0638edad50256f923294b
MD5 5188303b12900d399de2188446b6c42e
BLAKE2b-256 75c90ad4f038e9b6961576f2164ed6e401a9985f3c8a0a242e761241da244a3f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dec_browser-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2b7eedb6d7c0e8b3062962d8a616e7b1ec5cd98b382766474e2ead6cd02f0b8
MD5 f0572a1f7c156ec0e691ec69589368b1
BLAKE2b-256 d5963ce96441dfa46b4033f9bb18e58dab5e5aa7ba8c9e4f3bba3537b9dc4283

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