Browser elements define the parameters that can be passed to browser interactions. Each element type serves a specific purpose in browser automation.

WebElement

@dataclass
class WebElement:
    desc: str
    coordinates: Tuple[int, int]

Represents an element on the webpage with its description and coordinates.

Parameters

desc
string
required

Natural language description of the element (e.g., “login button”, “email input field”)

coordinates
Tuple[int, int]
required

X,Y coordinates of the element on the page

Example

button = WebElement(
    desc="Sign up button in the top right corner",
    coordinates=(100, 200)
)

# Validate the element
is_valid = button.validate()  # Returns True if both desc and coordinates are set

Text

@dataclass
class Text:
    body: str

Represents text input for typing actions.

Parameters

body
string
required

The text to be typed into an element

Example

text_input = Text(
    body="user@example.com"
)

# Validate the text
is_valid = text_input.validate()  # Returns True if body is not empty

Duration

@dataclass
class Duration:
    seconds: float

Represents a time duration for wait actions.

Parameters

seconds
float
required

Duration in seconds (can be fractional)

Example

wait_time = Duration(
    seconds=2.5
)

# Validate the duration
is_valid = wait_time.validate()  # Returns True if seconds is set

ActionParam Type

ActionParam is a union type that can be any of the above parameter types:

ActionParam = Union[WebElement, Text, Duration]

This allows browser interactions to accept different parameter types depending on the action being performed:

  • CLICK, SCROLL, HOVER actions require WebElement
  • TYPE actions require Text
  • WAIT actions require Duration

Usage with Browser Interactions

from enums import BrowserAction, BrowserInteraction, WebElement, Text, Duration

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

# Type interaction
type_text = BrowserInteraction(
    action=BrowserAction.TYPE,
    action_param=Text(
        body="Hello, world!"
    )
)

# Wait interaction
wait = BrowserInteraction(
    action=BrowserAction.WAIT,
    action_param=Duration(
        seconds=1.5
    )
)