Skip to content

Browser Actions

browser_actions

Pydantic models for headless browser automation.

Defines the strongly-typed contracts for the playWithBrowser feature of the Scrape.do API. It provides models for every supported browser interaction, enabling users to chain automation workflows with full type safety and IDE support.

ClickAction

Bases: BaseModel

Executes a click event on a specified CSS selector.

Attributes:

Name Type Description
action Literal['Click']

The literal action identifier.

selector str

The CSS selector of the target element.

WaitAction

Bases: BaseModel

Pauses browser execution for a specific duration.

Attributes:

Name Type Description
action Literal['Wait']

The literal action identifier.

timeout int

Number of milliseconds to wait.

WaitSelectorAction

Bases: BaseModel

Pauses browser execution until a specific element appears in the DOM.

Attributes:

Name Type Description
action Literal['WaitSelector']

The literal action identifier.

wait_selector str

The CSS selector to wait for.

timeout Optional[int]

Maximum time to wait in milliseconds. Defaults to None.

ScrollXAction

Bases: BaseModel

Scrolls the viewport horizontally.

Attributes:

Name Type Description
action Literal['ScrollX']

The literal action identifier.

value int

Number of pixels to scroll along the X-axis.

ScrollYAction

Bases: BaseModel

Scrolls the viewport vertically.

Attributes:

Name Type Description
action Literal['ScrollY']

The literal action identifier.

value int

Number of pixels to scroll along the Y-axis.

ScrollToAction

Bases: BaseModel

Scrolls the viewport until a specific element is visible.

Attributes:

Name Type Description
action Literal['ScrollTo']

The literal action identifier.

selector str

The CSS selector of the element to scroll to.

FillAction

Bases: BaseModel

Types a specified value into an input field.

Attributes:

Name Type Description
action Literal['Fill']

The literal action identifier.

selector str

The CSS selector of the input element.

value str

The text string to type into the element.

ExecuteAction

Bases: BaseModel

Executes arbitrary JavaScript within the browser context.

Attributes:

Name Type Description
action Literal['Execute']

The literal action identifier.

execute str

The raw JavaScript code to evaluate.

ScreenShotAction

Bases: BaseModel

Captures a screenshot during the execution of browser actions.

Attributes:

Name Type Description
action Literal['ScreenShot']

The literal action identifier.

full_screenshot Optional[bool]

If True, captures the entire scrollable page.

particular_screenshot Optional[str]

CSS selector of a specific element to capture.

validate_screenshot_logic()

Ensures mutually exclusive screenshot targeting parameters are not combined.

Capturing Full Screenshot And Particular Screenshot

A single screenshot action can either capture the entire scrollable page OR a specific DOM element, but not both simultaneously. To capture both, provide two separate ScreenShotAction objects in the play_with_browser list.

Returns:

Type Description
Self

The validated instance from which the method was called from

Raises:

Type Description
ValueError

If both full_screenshot and particular_screenshot are active.

WaitForRequestCompletionAction

Bases: BaseModel

Pauses execution until network requests matching a specific pattern complete.

Attributes:

Name Type Description
action Literal['WaitForRequestCompletion']

The literal action identifier.

url_pattern str

The regex or string pattern of the URL to wait for.

timeout int

Maximum time to wait in milliseconds before failing.

BrowserAction module-attribute

BrowserAction = Annotated[
    Union[
        ClickAction,
        WaitAction,
        WaitSelectorAction,
        ScrollXAction,
        ScrollYAction,
        ScrollToAction,
        FillAction,
        ExecuteAction,
        ScreenShotAction,
        WaitForRequestCompletionAction,
    ],
    Field(discriminator="action"),
]

Defines the valid types that can be passed to the play_with_browser parameter in the RequestParameters model