Browser interactions define how to interact with web elements. Each interaction combines an action type with its required parameters.

BrowserInteraction Class

@dataclass
class BrowserInteraction:
    action: BrowserAction
    action_param: ActionParam

Parameters

action
BrowserAction
required

The type of action to perform

action_param
ActionParam
required

Parameters required for the action (WebElement, Text, or Duration)

Available Actions

Click

BrowserAction.CLICK

Clicks at specific coordinates on the page. Requires a WebElement parameter.

Example:

click_interaction = BrowserInteraction(
    action=BrowserAction.CLICK,
    action_param=WebElement(
        desc="Sign up button",
        coordinates=(100, 200)
    )
)

Type

BrowserAction.TYPE

Types text into the active element. Requires a Text parameter.

Example:

type_interaction = BrowserInteraction(
    action=BrowserAction.TYPE,
    action_param=Text(
        body="user@example.com"
    )
)

Hover

BrowserAction.HOVER

Moves the mouse to specific coordinates. Requires a WebElement parameter.

Example:

hover_interaction = BrowserInteraction(
    action=BrowserAction.HOVER,
    action_param=WebElement(
        desc="Dropdown menu",
        coordinates=(150, 100)
    )
)

Scroll

BrowserAction.SCROLL

Scrolls the page vertically. Requires a WebElement parameter with target coordinates.

Example:

scroll_interaction = BrowserInteraction(
    action=BrowserAction.SCROLL,
    action_param=WebElement(
        desc="Bottom of page",
        coordinates=(0, 1000)
    )
)

Wait

BrowserAction.WAIT

Waits for a specified duration. Requires a Duration parameter.

Example:

wait_interaction = BrowserInteraction(
    action=BrowserAction.WAIT,
    action_param=Duration(
        seconds=2.5
    )
)

Validation

Each interaction can be validated to ensure it has the correct parameters:

interaction = BrowserInteraction(
    action=BrowserAction.CLICK,
    action_param=WebElement(
        desc="Submit button",
        coordinates=(200, 300)
    )
)

# Returns True if the interaction has valid parameters
is_valid = interaction.validate()