browserjquery package
browserjquery.jquery module
- class browserjquery.jquery.BrowserJQuery(driver: WebDriver | WebDriver)
Bases:
TextQueryMain class for jQuery-based browser interactions.
- attr(element: WebElement, attribute_name: str) str | None
Get attribute value of element.
- Args:
element: Element to get attribute from. attribute_name: Name of the attribute.
- Returns:
The attribute value or None if not found.
- children(element: WebElement, selector: str | None = None) list[WebElement]
Get direct children of element.
- Args:
element: Element to get children from. selector: Optional selector to filter children.
- Returns:
List of child WebElements.
- property document
Get the document element wrapped in jQuery.
- Returns:
The document element as a jQuery object.
- ensure_jquery()
Ensures that jQuery is injected into the page.
- Returns:
bool: True if jQuery is successfully injected, False otherwise.
- execute(script, *args)
Execute JavaScript on the page.
- Args:
script: The JavaScript code to execute. *args: Additional arguments to pass to the script.
- Returns:
The result of the JavaScript execution.
- find(selector: str, element: WebElement | None = None, *, first_match: bool = False) list[WebElement] | WebElement | None
Find elements using jQuery selector.
- Args:
selector: jQuery selector to find elements. element: Optional element to search within. If None, searches entire document. first_match: Whether to return only the first match.
- Returns:
Either a single WebElement, a list of WebElements, or None if no matches found.
- find_closest_ancestor(selector: str, element: WebElement) WebElement | None
Find the closest ancestor matching the selector.
- Args:
selector: jQuery selector to match ancestor. element: Element to start search from.
- Returns:
The closest matching ancestor WebElement or None if not found.
- has(element: WebElement, selector: str) bool
Check if element has descendants matching selector.
- Args:
element: Element to check. selector: jQuery selector to match descendants.
- Returns:
bool: True if element has matching descendants, False otherwise.
- has_class(element: WebElement, class_name: str) bool
Check if element has a specific class.
- Args:
element: Element to check. class_name: Class name to look for.
- Returns:
bool: True if element has the class, False otherwise.
- html(element: WebElement) str
Get HTML content of element.
- Args:
element: Element to get HTML from.
- Returns:
The HTML content of the element.
- inject_jquery(by: str = 'file', wait: int = 5) bool
Inject jQuery into the current page.
- Args:
by: Method of injection, either “file” or “cdn”. wait: Time to wait after injection in seconds.
- Returns:
bool: True if jQuery was successfully injected, False otherwise.
- is_checked(element: WebElement) bool
Check if checkbox/radio is checked.
- Args:
element: Element to check.
- Returns:
bool: True if element is checked, False otherwise.
- is_disabled(element: WebElement) bool
Check if element is disabled.
- Args:
element: Element to check.
- Returns:
bool: True if element is disabled, False otherwise.
- property is_jquery_injected: bool
Check if jQuery is already injected into the page.
- Returns:
bool: True if jQuery is present, False otherwise.
- is_visible(element: WebElement) bool
Check if element is visible.
- Args:
element: Element to check.
- Returns:
bool: True if element is visible, False otherwise.
- matches_selector(element: WebElement, selector: str) bool
Check if element matches a selector.
- Args:
element: Element to check. selector: jQuery selector to match against.
- Returns:
bool: True if element matches selector, False otherwise.
- next(element: WebElement, selector: str | None = None) list[WebElement] | WebElement | None
Get next sibling element.
- Args:
element: Element to get next sibling of. selector: Optional selector to filter next sibling.
- Returns:
Either a single WebElement, a list of WebElements, or None if not found.
- property page_html: str
Get the complete HTML of the current page.
- Returns:
str: The HTML content of the page.
- parent(element: WebElement) WebElement
Get the parent element.
- Args:
element: Element to get parent of.
- Returns:
The parent WebElement.
- parents(element: WebElement) list[WebElement]
Get all parent elements.
- Args:
element: Element to get parents of.
- Returns:
List of parent WebElements.
- prev(element: WebElement, selector: str | None = None) list[WebElement] | WebElement | None
Get previous sibling element.
- Args:
element: Element to get previous sibling of. selector: Optional selector to filter previous sibling.
- Returns:
Either a single WebElement, a list of WebElements, or None if not found.
- query(script: str, element: WebElement, *args)
Execute jQuery script on a specific element.
- Args:
script: The jQuery script to execute. element: The WebElement to execute the script on. *args: Additional arguments to pass to the script.
- Returns:
The result of the jQuery script execution.
- siblings(element: WebElement, selector: str | None = None) list[WebElement]
Get sibling elements.
- Args:
element: Element to get siblings of. selector: Optional selector to filter siblings.
- Returns:
List of sibling WebElements.
- text(element: WebElement) str
Get text content of element.
- Args:
element: Element to get text from.
- Returns:
The text content of the element.