Installation Guide

This guide will help you install and set up BrowserJQuery for your project.

Requirements

  • Python 3.8 or higher

  • Selenium WebDriver

  • Chrome or Firefox browser

Installation

Using pip

pip install browserjquery

Using Poetry

poetry add browserjquery

From Source

  1. Clone the repository:

git clone https://github.com/yourusername/browserjquery.git
cd browserjquery
  1. Install dependencies:

pip install -r requirements.txt
  1. Install the package:

pip install -e .

Setting Up Selenium WebDriver

Chrome WebDriver

  1. Install Chrome browser if not already installed

  2. Download ChromeDriver from ChromeDriver Downloads

  3. Add ChromeDriver to your system PATH

Firefox WebDriver

  1. Install Firefox browser if not already installed

  2. Download geckodriver from geckodriver Releases

  3. Add geckodriver to your system PATH

Basic Setup

from browserjquery import BrowserJQuery
from selenium import webdriver

# Initialize Chrome WebDriver
driver = webdriver.Chrome()
# Or Firefox
# driver = webdriver.Firefox()

# Create BrowserJQuery instance
browser = BrowserJQuery(driver)

# Navigate to a page
driver.get("https://example.com")

# Start using BrowserJQuery
elements = browser.find(".my-class")

Configuration

WebDriver Options

from selenium.webdriver.chrome.options import Options

# Configure Chrome options
options = Options()
options.add_argument("--headless")  # Run in headless mode
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")

# Initialize with options
driver = webdriver.Chrome(options=options)
browser = BrowserJQuery(driver)

jQuery Injection

BrowserJQuery automatically injects jQuery into pages. You can control this behavior:

# Check if jQuery is injected
if browser.is_jquery_injected:
    print("jQuery is available")

# Manually inject jQuery
browser.inject_jquery(by="file")  # From local file
browser.inject_jquery(by="cdn")   # From CDN

Troubleshooting

Common Issues

  1. WebDriver not found

    • Ensure WebDriver is installed and in your system PATH

    • Try specifying the WebDriver path explicitly:

      from selenium.webdriver.chrome.service import Service
      service = Service(path="/path/to/chromedriver")
      driver = webdriver.Chrome(service=service)
      
  2. jQuery injection fails

    • Check if the page already has jQuery

    • Try using a different injection method (file vs CDN)

    • Ensure the page is fully loaded before injection

  3. Element not found

    • Verify the selector syntax

    • Check if the element is in an iframe

    • Ensure the element is visible and loaded

Getting Help

  • Check the API Reference for detailed documentation

  • Look at Examples for usage patterns

  • Open an issue on GitHub for bugs or feature requests