Interact with a web page
act()
?act
enables Stagehand to perform individual actions on a web page. Use it to build self-healing and deterministic automations that adapt to website changes.
act()
?act()
act
to perform single actions in your automation. Here’s how to click a button:
act
, breaking complex actions into small, single-step actions works best. If you need to orchestrate multi-step flows, use multiple act
commands or agent
.
Suggested actions
Action | Example instruction |
---|---|
Click | click the button |
Fill | fill the field with <value> |
Type | type <text> into the search box |
Press | press <key> in the search field |
Scroll | scroll to <position> |
Select from dropdown | select <value> from the dropdown |
experimental: true
in your Stagehand configuration to enable it. See the configuration guide for more details.observe()
to discover candidate actions on the current page and plan reliably. It returns a list of suggested actions (with selector, description, method, and arguments). You can pass an observed action directly to act
to execute it.
observe()
before executing with act
..env
files. Never hardcode API keys, passwords, or other secrets directly in your code.verbose: 0
in your Stagehand configuration to prevent secrets from appearing in logs. See the configuration guide for more details.Method not supported
act
fails with “method not supported” errorSolutions:observe()
and verify the resulting action is within a list of expected actionsAction failed or timed out
act
times out or fails to complete action (often due to element not found)Solutions:observe()
first to verify element existsIncorrect element selected
act
performs action on wrong elementSolutions:observe()
to preview which element will be selectedAgent
to autonomously execute multi-step tasks and complex workflows.extract
with a data schema to pull clean, typed data from any page.