Skip to content

API Reference parrot_tools.scraping.drivers.abstract

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.scraping.drivers.abstract

View source

Abstract driver interface for browser automation.

Defines the unified AbstractDriver ABC that all browser automation drivers (Selenium, Playwright, etc.) must implement.

Class AbstractDriver

Unified interface for browser automation drivers.

All driver-specific capabilities are exposed through this interface. Concrete drivers implement the abstract methods for their backend. Methods not supported by a driver raise NotImplementedError with a clear message indicating which driver does support the feature.

Attributes:

Attribute Type Description
current_url str The URL of the current page.

Method AbstractDriver.start

Initialize the browser and create a default page/tab.

start() -> None

Method AbstractDriver.quit

Close the browser and release all resources.

quit() -> None

Method AbstractDriver.navigate

Navigate to url.

navigate(url: str, timeout: int = 30) -> None

Parameter Type Default Description
url str The URL to navigate to.
timeout int 30 Maximum wait time in seconds.

Method AbstractDriver.go_back

Navigate back in history.

go_back() -> None

Method AbstractDriver.go_forward

Navigate forward in history.

go_forward() -> None

Method AbstractDriver.reload

Reload the current page.

reload() -> None

Method AbstractDriver.click

Click the element matching selector.

click(selector: str, timeout: int = 10) -> None

Parameter Type Default Description
selector str CSS selector (or driver-specific selector).
timeout int 10 Maximum wait time in seconds.

Method AbstractDriver.fill

Clear and fill the input matching selector with value.

fill(selector: str, value: str, timeout: int = 10) -> None

Parameter Type Default Description
selector str CSS selector for the input element.
value str Text to type into the input.
timeout int 10 Maximum wait time in seconds.

Method AbstractDriver.select_option

Select an option in a <select> element.

select_option(selector: str, value: str, *, by: Literal['value', 'text', 'index'] = 'value', timeout: int = 10) -> None

Parameter Type Default Description
selector str CSS selector for the select element.
value str The option value, visible text, or index to select.
by Literal['value', 'text', 'index'] 'value' Selection mode — "value" (default), "text" (visible text), or "index" (0-based integer index passed as a string).
timeout int 10 Maximum wait time in seconds.

Method AbstractDriver.hover

Hover over the element matching selector.

hover(selector: str, timeout: int = 10) -> None

Parameter Type Default Description
selector str CSS selector.
timeout int 10 Maximum wait time in seconds.

Method AbstractDriver.press_key

Press a keyboard key.

press_key(key: str) -> None

Parameter Type Default Description
key str Key name (e.g. "Enter", "Tab", "Escape").

Method AbstractDriver.get_page_source

Return the full HTML source of the current page.

get_page_source() -> str

Returns: str

Method AbstractDriver.get_text

Return the inner text of the element matching selector.

get_text(selector: str, timeout: int = 10) -> str

Parameter Type Default Description
selector str CSS selector.
timeout int 10 Maximum wait time in seconds.

Returns: str

Method AbstractDriver.get_attribute

Return the value of attribute on the element matching selector.

get_attribute(selector: str, attribute: str, timeout: int = 10) -> Optional[str]

Parameter Type Default Description
selector str CSS selector.
attribute str Attribute name (e.g. "href", "src").
timeout int 10 Maximum wait time in seconds.

Returns: Optional[str] — Attribute value, or None if not present.

Method AbstractDriver.get_all_texts

Return the inner text of every element matching selector.

get_all_texts(selector: str, timeout: int = 10) -> List[str]

Parameter Type Default Description
selector str CSS selector matching one or more elements.
timeout int 10 Maximum wait time in seconds.

Returns: List[str]

Method AbstractDriver.screenshot

Take a screenshot of the current page.

screenshot(path: str, full_page: bool = False) -> bytes

Parameter Type Default Description
path str File path to save the screenshot.
full_page bool False If True, capture the full scrollable page.

Returns: bytes — Raw screenshot bytes.

Method AbstractDriver.type_text

Type keystrokes; optionally select and clear a target, with delay in milliseconds.

type_text(text: str, selector: Optional[str] = None, delay_ms: int = 0, clear_first: bool = False, timeout: int = 10) -> None

Parameter Type Default Description
text str
selector Optional[str] None
delay_ms int 0
clear_first bool False
timeout int 10

Raises:

  • NotImplementedError — The current driver does not support typing text.

Method AbstractDriver.screenshot_element

Save an element PNG to path and return its raw bytes; timeout is seconds.

screenshot_element(selector: str, path: str, timeout: int = 10) -> bytes

Parameter Type Default Description
selector str
path str
timeout int 10

Returns: bytes

Raises:

  • NotImplementedError — The current driver does not support element screenshots.

Method AbstractDriver.wait_for_selector

Wait until an element matching selector reaches state.

wait_for_selector(selector: str, timeout: int = 10, state: str = 'visible') -> None

Parameter Type Default Description
selector str CSS selector.
timeout int 10 Maximum wait time in seconds.
state str 'visible' Target state — "visible", "hidden", "attached", or "detached".

Method AbstractDriver.wait_for_navigation

Wait for a navigation event to complete.

wait_for_navigation(timeout: int = 30) -> None

Parameter Type Default Description
timeout int 30 Maximum wait time in seconds.

Method AbstractDriver.wait_for_load_state

Wait until the page reaches the given load state.

wait_for_load_state(state: str = 'load', timeout: int = 30) -> None

Parameter Type Default Description
state str 'load' "load", "domcontentloaded", or "networkidle".
timeout int 30 Maximum wait time in seconds.

Method AbstractDriver.execute_script

Execute JavaScript in the page context.

execute_script(script: str, *args: Any) -> Any

Parameter Type Default Description
script str JavaScript source code.
*args Any () Arguments passed to the script.

Returns: Any — The return value of the script.

Method AbstractDriver.evaluate

Evaluate a JavaScript expression and return the result.

evaluate(expression: str) -> Any

Parameter Type Default Description
expression str JavaScript expression to evaluate.

Returns: Any — The expression result.

Method AbstractDriver.get_cookies

Return browser-context cookies, HttpOnly included.

get_cookies(urls: Optional[Sequence[str]] = None) -> List[Dict[str, Any]]

Parameter Type Default Description
urls Optional[Sequence[str]] None Restrict to cookies that would be sent to these URLs; None = all.

Returns: List[Dict[str, Any]] — Cookie dicts (name, value, domain, path, httpOnly, secure, ...).

Raises:

  • NotImplementedError — The driver cannot read context-level cookies.

Method AbstractDriver.intercept_requests

Set up a request interception handler.

intercept_requests(handler: Callable) -> None

Parameter Type Default Description
handler Callable Async callable receiving (route, request).

Raises:

  • NotImplementedError — If the driver does not support request interception.

Method AbstractDriver.record_har

Start recording a HAR file.

record_har(path: str) -> None

Parameter Type Default Description
path str File path for the HAR output.

Raises:

  • NotImplementedError — If the driver does not support HAR recording.

Method AbstractDriver.save_pdf

Save the current page as a PDF.

save_pdf(path: str) -> bytes

Parameter Type Default Description
path str File path for the PDF output.

Returns: bytes — Raw PDF bytes.

Raises:

  • NotImplementedError — If the driver does not support native PDF export.

Method AbstractDriver.start_tracing

Start tracing browser activity.

start_tracing(name: str = 'trace', screenshots: bool = True, snapshots: bool = True) -> None

Parameter Type Default Description
name str 'trace' Trace name / title.
screenshots bool True Capture screenshots in the trace.
snapshots bool True Capture DOM snapshots in the trace.

Raises:

  • NotImplementedError — If the driver does not support tracing.

Method AbstractDriver.stop_tracing

Stop tracing and save to path.

stop_tracing(path: str) -> None

Parameter Type Default Description
path str File path for the trace archive.

Raises:

  • NotImplementedError — If the driver does not support tracing.

Method AbstractDriver.mock_route

Mock network requests matching url_pattern.

mock_route(url_pattern: str, handler: Callable) -> None

Parameter Type Default Description
url_pattern str Glob or regex pattern to match request URLs.
handler Callable Async callable to handle matched requests.

Raises:

  • NotImplementedError — If the driver does not support route mocking.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally