Chapter 5: Bot Development Fundamentals
Learn bot creation and automation scripting concepts. Understand how to design, build, test and improve basic software robots for repetitive business processes.
Bot Flow
Actions
Automation
Robot
5.1 Chapter Overview
Bot development is the process of creating software robots that can perform repetitive digital tasks. A bot follows instructions designed by a developer or automation analyst. These instructions may include opening applications, reading files, copying data, entering records, sending emails, validating information and generating reports.
This chapter introduces learners to the fundamentals of bot creation and automation scripting. The focus is on understanding how a bot is planned, designed, built, tested and monitored.
5.2 Learning Objectives
- Understand the meaning of software bots and bot development.
- Identify the components of a bot workflow.
- Use basic automation logic such as sequence, condition and loop.
- Understand variables, inputs, outputs and data types in automation.
- Explain selectors, UI elements and screen interaction concepts.
- Understand automation scripting concepts used in RPA tools.
- Apply error handling and logging concepts.
- Design and build a basic software robot workflow.
5.3 What is a Software Bot?
A software bot is a digital worker that follows predefined instructions to perform tasks on a computer. Unlike a human user, a bot does not get tired, can run repeatedly and can complete structured tasks with high consistency.
| Bot Capability | Example |
|---|---|
| Open applications | Open browser, Excel, ERP or email system |
| Read data | Read Excel sheet, PDF, email or web form |
| Enter data | Type customer record into CRM |
| Click buttons | Submit form or download report |
| Make rule-based decisions | If invoice amount is above limit, send for approval |
| Send notifications | Email manager after task completion |
5.4 Bot Development Lifecycle
Bot development should follow a structured lifecycle to ensure that the bot is reliable, secure and useful.
| Stage | Description | Deliverable |
|---|---|---|
| Process Understanding | Study the manual process and business rules. | Process map |
| Requirement Documentation | Define input, output, systems, exceptions and success criteria. | Process design document |
| Bot Design | Plan bot steps, logic, variables and decision points. | Bot workflow diagram |
| Bot Development | Build automation using RPA tool or script. | Working bot |
| Testing | Test with normal and exception cases. | Test report |
| Deployment | Move bot to production environment. | Live automation |
| Monitoring | Track logs, errors and performance. | Bot monitoring dashboard |
5.5 Automation Logic
Automation logic defines how the bot should behave. The three most important logic structures are sequence, condition and loop.
Sequence
Steps run one after another in order.
Condition
Bot chooses a path based on a rule.
Loop
Bot repeats steps for multiple records.
Example: Invoice Approval Logic
↓
If Amount > RM 5,000 → Send Manager Approval
Else → Process Payment Automatically
Pseudocode Example
read invoice_amount
if invoice_amount > 5000:
send_to_manager_approval
else:
process_payment
send_confirmation_email5.6 Variables, Inputs and Outputs
Variables store information used by the bot during execution. For example, a bot may store invoice number, customer name, amount, approval status and email address.
| Variable Name | Data Type | Example Value | Use |
|---|---|---|---|
| invoice_number | Text | INV-10025 | Identify invoice |
| invoice_amount | Number | 3500 | Check approval rule |
| is_approved | Boolean | True | Decision making |
| customer_email | Text | customer@email.com | Send notification |
| process_date | Date | 2026-06-02 | Record processing date |
5.7 Working with Data Tables
Many bots process rows of data from Excel, CSV files or databases. A bot may loop through each row and perform the same action repeatedly.
Example: Customer Update Bot
| Customer ID | Name | Status | Bot Action |
|---|---|---|---|
| C001 | Amin | Active | Update CRM |
| C002 | Mei Ling | Inactive | Skip or flag |
| C003 | Ravi | Active | Update CRM |
for each row in customer_table:
read customer_id
read status
if status == "Active":
update_crm_record
else:
add_to_exception_report5.8 UI Elements and Selectors
When a bot interacts with applications, it needs to identify screen elements such as buttons, text boxes, menus and tables. Selectors are used by many RPA tools to locate these UI elements reliably.
| UI Element | Bot Action | Example |
|---|---|---|
| Text Box | Type data | Enter customer name |
| Button | Click | Click Submit |
| Dropdown | Select option | Select department |
| Table | Read rows | Extract invoice list |
| Web Link | Navigate | Open report page |
5.9 Automation Scripting Concepts
Most RPA tools use visual workflows, but scripting concepts are still important. Developers must understand logic, variables, loops and error handling. Some automations may also use Python, JavaScript, PowerShell or VB.NET scripts.
Python Example: Rename Files Automatically
import os
folder_path = "reports"
for filename in os.listdir(folder_path):
if filename.endswith(".xlsx"):
old_path = os.path.join(folder_path, filename)
new_name = "PDTC_" + filename
new_path = os.path.join(folder_path, new_name)
os.rename(old_path, new_path)
print("Files renamed successfully.")All Excel files in the reports folder are renamed with PDTC_ prefix.
Line-by-Line Explanation
| Code | Explanation |
|---|---|
| import os | Imports Python library for file and folder operations. |
| os.listdir(folder_path) | Gets all files inside the folder. |
| filename.endswith(".xlsx") | Checks if the file is an Excel file. |
| os.rename() | Renames the file. |
5.10 Email Automation Concept
Email automation is one of the most common bot use cases. A bot can read emails, download attachments, classify requests and send replies.
Email Bot Pseudocode
open mailbox
for each unread email:
read subject
if subject contains "Invoice":
download attachment
process invoice
send confirmation
else:
move email to review folder5.11 Error Handling and Exceptions
A reliable bot must handle errors properly. Errors can happen when a file is missing, a website is down, login fails, data is invalid or an application layout changes.
| Error Type | Example | Handling Method |
|---|---|---|
| Missing File | Excel file not found | Log error and notify user |
| Invalid Data | Invoice amount is blank | Add record to exception report |
| Login Failure | Password expired | Stop process and alert admin |
| System Timeout | ERP page not loading | Retry after waiting |
| Selector Failure | Submit button not found | Use fallback selector or raise exception |
Try-Except Concept
try:
open_excel_file
read_invoice_data
update_erp_system
except:
log_error
send_alert_email5.12 Logging and Audit Trail
Logs help track what the bot did. A good bot should record start time, end time, number of records processed, errors and final status.
| Log Field | Example |
|---|---|
| Bot Name | Invoice Processing Bot |
| Start Time | 08:00 AM |
| End Time | 08:15 AM |
| Records Processed | 120 |
| Successful Records | 115 |
| Exception Records | 5 |
| Status | Completed with exceptions |
5.13 Mini Project: Basic Invoice Entry Bot
This mini project explains how a basic bot can process invoices from Excel and enter data into a business system.
Bot Requirements
- Read invoice records from Excel.
- Validate invoice number and amount.
- Open accounting system.
- Enter invoice details.
- Submit record.
- Save success or failure status in log file.
Bot Workflow
Sample Pseudocode
open invoice_excel_file
for each invoice in file:
if invoice_number is empty:
write "Missing invoice number" to exception_log
continue
if invoice_amount <= 0:
write "Invalid amount" to exception_log
continue
open accounting_system
enter invoice_number
enter invoice_amount
click submit
write "Success" to process_log
send completion_email5.14 Best Practices for Bot Development
| Best Practice | Reason |
|---|---|
| Use clear naming | Makes workflow easier to understand. |
| Break large process into smaller steps | Improves maintenance and testing. |
| Validate input data | Prevents wrong processing. |
| Add exception handling | Prevents bot failure from stopping entire process. |
| Create logs | Supports audit and troubleshooting. |
| Test with real scenarios | Improves reliability. |
| Protect credentials | Improves security. |
5.15 Practical Activities
Activity 1: Bot Workflow Design
Design a bot workflow for processing student attendance from Excel and sending a report to the trainer.
Activity 2: Variable Identification
List five variables required for an invoice processing bot. Include variable name, data type and purpose.
Activity 3: Error Handling
Identify five possible errors that may happen in an email automation bot and suggest handling methods.
Mini Project: Report Generation Bot
Create a process design for a bot that reads data from Excel, generates a PDF report and emails it to management.
5.16 Interactive Final Assessment Quiz
Each correct answer gives +1 mark.
Each wrong answer gives -0.5 mark.
1. A software bot follows predefined instructions to perform tasks.
2. Which logic structure repeats steps for multiple records?
3. Variables are used to store information during bot execution.
4. Which is an example of a UI element?
5. Error handling helps bots manage unexpected situations.
6. Logs are useful for audit and troubleshooting.
7. Which variable name is clearer?
8. A bot should be tested before deployment.
9. Which is a common bot input source?
10. A reliable bot should include exception handling and logging.
Your Score: 0
5.17 Chapter Summary
In this chapter, learners studied bot development fundamentals, software bot concepts, automation logic, variables, data tables, UI selectors, automation scripting, error handling, logging and basic bot project design.