await page.act("click on add to cart");

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".

You can define variables that will not be shared with LLM providers

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

Small atomic goals perform the best. Avoid using act() to perform complex actions. For multi-step actions, use Agent instead

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

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

timeoutMs
number

Timeout in milliseconds for the action being performed.

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