Skip to main content
This example demonstrates how to automate complex forms, including handling dynamic fields, dropdowns, and file uploads using a real Twitter account creation flow.

Complete example

Here’s a complete example that automates Twitter account creation:

Step-by-step breakdown

1

Handle dynamic fields

Forms often change based on user input or location. Handle this gracefully:
2

Fill text inputs

Send text to input fields using send_keys():
3

Handle dropdowns

Select options from dropdown menus:
4

Submit the form

Find and click the submit button:

File upload example

Here’s how to upload files to a form (from the Imgur example):

Key techniques

Working with multiple fields

Use unpacking to assign multiple elements at once:

Handling conditional elements

Waiting for form updates

When dealing with JavaScript-heavy sites, use await tab.wait(seconds) or await tab to give the page time to render dynamic content.

Advanced patterns

Finding elements by placeholder

When text is in a placeholder attribute rather than a text node:

Using CSS attribute selectors

File uploads take time to process. Always wait for confirmation (like a toast message or progress indicator) before continuing.