WebElement
pydoll.elements.web_element.WebElement
Bases: FindElementsMixin
DOM element wrapper for browser automation.
Provides comprehensive functionality for element interaction, inspection, and manipulation using Chrome DevTools Protocol commands.
Initialize WebElement wrapper.
PARAMETER | DESCRIPTION |
---|---|
object_id
|
Unique CDP object identifier for this DOM element.
TYPE:
|
connection_handler
|
Connection instance for browser communication.
TYPE:
|
method
|
Search method used to find this element (for debugging).
TYPE:
|
selector
|
Selector string used to find this element (for debugging).
TYPE:
|
attributes_list
|
Flat list of alternating attribute names and values.
TYPE:
|
bounds
async
property
Element's bounding box coordinates.
Returns coordinates in CSS pixels relative to document origin.
get_bounds_using_js
async
Get element bounds using JavaScript getBoundingClientRect().
Returns coordinates relative to viewport (alternative to bounds property).
take_screenshot
async
Capture screenshot of this element only.
Automatically scrolls element into view before capturing.
get_attribute
Get element attribute value.
Note
Only provides attributes available when element was located. For dynamic attributes, consider using JavaScript execution.
click_using_js
async
Click element using JavaScript click() method.
RAISES | DESCRIPTION |
---|---|
ElementNotVisible
|
If element is not visible. |
ElementNotInteractable
|
If element couldn't be clicked. |
Note
For
click
async
Click element using simulated mouse events.
PARAMETER | DESCRIPTION |
---|---|
x_offset
|
Horizontal offset from element center.
TYPE:
|
y_offset
|
Vertical offset from element center.
TYPE:
|
hold_time
|
Duration to hold mouse button down.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ElementNotVisible
|
If element is not visible. |
Note
For
insert_text
async
Insert text in single operation (faster but less realistic than typing).
Note
Element should already be focused for text to be inserted correctly.
set_input_files
async
Set file paths for file input element.
PARAMETER | DESCRIPTION |
---|---|
files
|
list of absolute file paths to existing files.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ElementNotAFileInput
|
If element is not a file input. |
type_text
async
Type text character by character with realistic timing.
More realistic than insert_text() but slower.
key_down
async
Send key down event.
Note
Only sends key down without release. Pair with key_up() for complete keypress.
press_keyboard_key
async
Press and release keyboard key with configurable timing.
Better for special keys (Enter, Tab, etc.) than type_text().
find
async
find(id=None, class_name=None, name=None, tag_name=None, text=None, timeout=0, find_all=False, raise_exc=True, **attributes)
Find element(s) using combination of common HTML attributes.
Flexible element location using standard attributes. Multiple attributes can be combined for specific selectors (builds XPath when multiple specified).
PARAMETER | DESCRIPTION |
---|---|
id
|
Element ID attribute value.
TYPE:
|
class_name
|
CSS class name to match.
TYPE:
|
name
|
Element name attribute value.
TYPE:
|
tag_name
|
HTML tag name (e.g., "div", "input").
TYPE:
|
text
|
Text content to match within element.
TYPE:
|
timeout
|
Maximum seconds to wait for elements to appear.
TYPE:
|
find_all
|
If True, returns all matches; if False, first match only.
TYPE:
|
raise_exc
|
Whether to raise exception if no elements found.
TYPE:
|
**attributes
|
Additional HTML attributes to match.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[WebElement, list[WebElement], None]
|
WebElement, list[WebElement], or None based on find_all and raise_exc. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If no search criteria provided. |
ElementNotFound
|
If no elements found and raise_exc=True. |
WaitElementTimeout
|
If timeout specified and no elements appear in time. |
query
async
Find element(s) using raw CSS selector or XPath expression.
Direct access using CSS or XPath syntax. Selector type automatically determined based on expression pattern.
PARAMETER | DESCRIPTION |
---|---|
expression
|
Selector expression (CSS, XPath, ID with #, class with .).
TYPE:
|
timeout
|
Maximum seconds to wait for elements to appear.
TYPE:
|
find_all
|
If True, returns all matches; if False, first match only.
TYPE:
|
raise_exc
|
Whether to raise exception if no elements found.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[WebElement, list[WebElement], None]
|
WebElement, list[WebElement], or None based on find_all and raise_exc. |
RAISES | DESCRIPTION |
---|---|
ElementNotFound
|
If no elements found and raise_exc=True. |
WaitElementTimeout
|
If timeout specified and no elements appear in time. |
find_or_wait_element
async
Core element finding method with optional waiting capability.
Searches for elements with flexible waiting. If timeout specified, repeatedly attempts to find elements with 0.5s delays until success or timeout. Used by higher-level find() and query() methods.
PARAMETER | DESCRIPTION |
---|---|
by
|
Selector strategy (CSS_SELECTOR, XPATH, ID, etc.).
TYPE:
|
value
|
Selector value to locate element(s).
TYPE:
|
timeout
|
Maximum seconds to wait (0 = no waiting).
TYPE:
|
find_all
|
If True, returns all matches; if False, first match only.
TYPE:
|
raise_exc
|
Whether to raise exception if no elements found.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[WebElement, list[WebElement], None]
|
WebElement, list[WebElement], or None based on find_all and raise_exc. |
RAISES | DESCRIPTION |
---|---|
ElementNotFound
|
If no elements found with timeout=0 and raise_exc=True. |
WaitElementTimeout
|
If elements not found within timeout and raise_exc=True. |