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.0.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.

dec_browser-1.0.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dec_browser-1.0.0.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 dec_browser-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f8f7b3fd6cca33a218536d3033d924a86498a93ecc53b6e243ec5865b38d5d90
MD5 ab7ac0ee34ea2ad7d37daf77c7d823ff
BLAKE2b-256 578b4200f669ec6fac707b1df36225b2358f92734601852971d40cfef6f37395

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dec_browser-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 845b91afadcf230b470f8c830828634b399a3134640af629eb6592742d5a216f
MD5 792d34ba7455cdef2374328faf33b36e
BLAKE2b-256 a5d0fe4c848b3e329ac6655a1aa723b76cd7f87b650aa873e664a1e26fbbab1a

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