如何在Automation Anywhere中逐行读取Excel数据并自动填充至网页表单?
Got it, let's walk through exactly how to build this Automation Anywhere bot that reads Excel rows and fills web forms—this is a super common use case, so I'll break it down step by step so you can follow along easily.
Step-by-Step Guide to Build the Automation Anywhere Bot
1. Pre-Requisites & Quick Setup
First, make sure you have these sorted before starting:
- Automation Anywhere Enterprise or Community Edition installed and running
- Your target Excel file cleaned up: no merged cells, clear headers (e.g., Row 1 = "Name", "Email", "Phone"), and all data rows are contiguous
- Manual test run of the web form done: note down each input field's identifier (ID, name, or XPath) and the submit button location—this will save you time during bot building
2. Build the Core Workflow
Let's dive into the bot commands:
2.1 Start an Excel Session
- Drag the Excel Advanced command into your workflow (the advanced module is more flexible than basic Excel commands for this task)
- Select
Open Workbook, browse to your Excel file path, checkOpen in Read-Only Mode(to avoid locking the file), and name the session something likeExcel_Data_Session—this lets you reference it later easily
2.2 Get Total Rows to Loop Through
- Still in Excel Advanced, add a
Get Worksheet Rangecommand - Pick your target worksheet (e.g., Sheet1), and configure it to fetch the total number of rows in your data range. Store this value in a numeric variable like
Total_Rows - Pro tip: If your headers are in Row 1, your data starts at Row 2—so your loop will run from Row 2 to
Total_Rows
2.3 Set Up a Row-by-Row Loop
- Drag a Loop command into the workflow, select the
For Rangetype - Set the start row to
2, end row to${Total_Rows}, and step to1. Store the current row number in a variable likeCurrent_Row—this will track which row we're processing
2.4 Read Data from the Current Row
Inside the loop, add Get Cell Value commands for each column you need to extract:
- For example, if Name is in Column A: set the cell to
A${Current_Row}, select yourExcel_Data_Session, and save the value toVar_Name - Repeat this for every field: Email (Column B →
Var_Email), Phone (Column C →Var_Phone), etc.
2.5 Fill the Web Form
Now it's time to interact with the web form:
- Add an
Open Browsercommand, input your form's URL, and select your preferred browser (Chrome works great for most cases) - For each input field, add a
Set Textcommand from the Web module:- Locate the field using its ID, name, or XPath (ID/Name is more stable if available)
- Paste the corresponding variable into the text field (e.g.,
${Var_Name}for the name input)
- Once all fields are filled, add a
Clickcommand to hit the submit button—again, use a stable selector for the button
2.6 Clean Up for the Next Row
After submitting, you can either:
- Close the current browser tab with a
Close Tabcommand, or - Refresh the page with a
Refreshcommand to reset the form for the next entry - The loop will automatically move to the next row until all rows are processed
2.7 Close the Excel Session
Once the loop finishes, add a Close Workbook command from Excel Advanced, select your Excel_Data_Session, and uncheck Save Changes (since we're only reading the file)
3. Pro Tips to Avoid Headaches
- Skip Empty Rows: Add an
Ifcommand at the start of the loop to check if a key field (likeVar_Name) is empty. If it is, use aContinuecommand to skip to the next row - Wait for Elements: Before filling each field, add a
Wait for Elementcommand to ensure the web page has loaded completely—this prevents "element not found" errors - Error Handling: Wrap the web form section in a
Try-Catchblock. If an error occurs (e.g., page timeout), log the error to a file and useContinueto keep the bot running - Test Small First: Run the bot with 2-3 test rows first to iron out any kinks before processing the entire dataset
内容的提问来源于stack exchange,提问作者KIRTI SAGAR




