// Basic usage
 await page.act({ action: "click on add to cart" });

 // Using variables
 await page.act({
   action: "enter %username% into the username field",
   variables: {
     username: "john.doe@example.com",
   },
 });

 // Multiple variables
 await page.act({
   action: "fill in the form with %username% and %password%",
   variables: {
     username: "john.doe",
     password: "secretpass123",
   },
 });

act() allows Stagehand to interact with a web page. Provide an action like "Click on the add to cart button", or "Type 'Browserbase' into the search bar".

Small atomic goals perform the best. Avoid using act() to perform complex actions.

You can pass an ObserveResult to act() to perform the suggested action, which will yield a faster and cheaper result (no LLM inference).

Arguments: ActOptions | ObserveResult

ActOptions:

action
string
required

Describes the action to perform

modelName
AvailableModel

Specifies the model to use

modelClientOptions
object

Configuration options for the model client

useVision
boolean | 'fallback'

Determines if vision-based processing should be used. Defaults to “fallback”

variables
Record<string, string>

Variables to use in the action. Variables in the action string are referenced using %variable_name%

domSettleTimeoutMs
number

Timeout in milliseconds for waiting for the DOM to settle

ObserveResult:

selector
string
required

A string representing the element selector

description
string
required

A string describing the possible action

method
string
required

The method to call on the element

arguments
object
required

The arguments to pass to the method

Returns: Promise<ActResult>

success
boolean
required

If the action was completed successfully

message
string
required

Details about the action’s execution

action
string
required

The action performed