Browser Automation with Claude

Forms and Authentication

5 min read

Handling forms and login flows is essential for web automation. Claude can fill forms, handle multi-step authentication, and manage sessions.

Form Filling Basics

task = """
Fill the contact form:
1. Enter 'John Doe' in the Name field
2. Enter 'john@example.com' in Email
3. Select 'General Inquiry' from the dropdown
4. Type a message about your product
5. Click Submit
"""

Field Detection

Claude identifies form fields by:

  • Labels (text near input)
  • Placeholder text
  • Field type (text, email, password)
  • Position and context
task = """
1. Click the Country dropdown
2. Scroll to find 'United States'
3. Click to select it
4. Verify the selection
"""

Login Flows

task = """
Log into the dashboard:
1. Click 'Sign In'
2. Enter the username: user@example.com
3. Enter the password: [provided password]
4. Click 'Log In'
5. Wait for redirect to dashboard
6. Confirm successful login
"""

Multi-Factor Authentication

Handle 2FA flows:

task = """
Complete the login with 2FA:
1. Enter credentials
2. Wait for 2FA prompt
3. When you see the code input, STOP and ask me for the code
"""

Handling CAPTCHAs

Claude cannot solve CAPTCHAs (by design). Handle gracefully:

task = """
Try to submit the form.
If you encounter a CAPTCHA:
1. Report that a CAPTCHA is present
2. Stop and wait for human intervention
"""

Session Management

Maintain login state across tasks:

# Use browser profiles or session storage
task = """
1. Check if already logged in
2. If not, perform login
3. Navigate to settings
4. Update the profile
"""

Form Validation Handling

task = """
Submit the form:
1. Fill all fields
2. Click Submit
3. If validation errors appear:
   - Read the error messages
   - Fix the indicated fields
   - Try again
4. Report success or remaining errors
"""

Best Practices

Practice Reason
Verify field focus Ensure correct input target
Tab between fields More reliable than clicking
Check for errors Handle validation feedback
Confirm submission Verify success message

Security: Never store credentials in code. Use environment variables or secure vaults.

Next, we'll explore data extraction from web pages. :::

Quiz

Module 4: Browser Automation

Take Quiz