Overview
The Undetected library provides custom WebElement classes that extend Selenium’s standard WebElement with additional functionality for safer interactions and better debugging capabilities.WebElement
Enhanced WebElement class that extendsselenium.webdriver.remote.webelement.WebElement with safe click operations and child element queries.
Methods
click_safe()
Performs a click operation followed by a driver reconnection to maintain stability.
click() method and then reconnects the parent driver with a 0.1 second delay, helping to maintain connection stability after interactions.
children(tag=None, recursive=False)
Returns direct child elements of the current element.
If supplied, returns only child elements with the specified tag name (e.g., ‘div’, ‘a’, ‘img’)
If True, returns all descendant elements recursively instead of just direct children
- Uses JavaScript execution to query child elements
- Tag filtering is case-insensitive (automatically converts to uppercase)
- Recursive mode uses the
_recursive_childrenhelper function
UCWebElement
Custom WebElement class that provides enhanced representation for better debugging in interactive environments.Overview
UCWebElement extends WebElement with improved string representation, making it easier to view elements when working in an interactive environment like Jupyter notebooks or Python REPL.
Standard WebElement representation:
Properties
attrs
Returns a dictionary containing all HTML attributes of the element.
- Lazily loaded on first access
- Cached after first retrieval
- Uses JavaScript execution to extract all element attributes
Methods
__repr__()
Returns a human-readable string representation of the element showing its tag name and attributes.
Helper Functions
_recursive_children(element, tag=None, _results=None)
Internal helper function that recursively collects all descendant elements.
The WebElement to find children below
If provided, returns only elements with the specified tag name (e.g., ‘a’, ‘img’)
Internal parameter for recursion - do not use directly
children() method when recursive=True is specified.