This example demonstrates how to fill out a contact form with specific information:
import asynciofrom browser_use import Agent, ChatBrowserUsefrom dotenv import load_dotenvload_dotenv()async def main(): # Initialize the model llm = ChatBrowserUse(model='bu-2-0') # Define a form filling task task = """ Go to https://httpbin.org/forms/post and fill out the contact form with: - Customer name: John Doe - Telephone: 555-123-4567 - Email: john.doe@example.com - Size: Medium - Topping: cheese - Delivery time: now - Comments: This is a test form submission Then submit the form and tell me what response you get. """ # Create and run the agent agent = Agent(task=task, llm=llm) await agent.run()if __name__ == '__main__': asyncio.run(main())
For complex forms with multiple sections, you can provide detailed instructions:
task = """Fill out the registration form with:Personal Information:- First Name: Jane- Last Name: Smith- Email: jane.smith@example.com- Phone: (555) 123-4567Address:- Street: 123 Main St- City: San Francisco- State: CA- ZIP: 94102Preferences:- Newsletter: Yes- Contact method: EmailThen click the Submit button and confirm the registration."""agent = Agent(task=task, llm=ChatBrowserUse())await agent.run()
The agent can verify that forms were filled correctly:
task = """Fill out the contact form with my information:- Name: John Doe- Email: john@example.comAfter filling, verify that:1. All required fields are filled (look for red asterisks)2. Email format is valid (no error messages)3. Submit the form only if validation passes"""