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 Creation Automation Logic Variables Selectors Error Handling
Design
Bot Flow
Build
Actions
Test
Automation
Run
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.

Learning Outcome: By the end of this chapter, learners should be able to explain bot development concepts, design basic automation logic, understand variables and conditions, apply simple scripting ideas, handle exceptions and build simple software robot workflows.
1Understand Task
2Design Bot Steps
3Build Actions
4Test Bot
5Deploy Bot

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 CapabilityExample
Open applicationsOpen browser, Excel, ERP or email system
Read dataRead Excel sheet, PDF, email or web form
Enter dataType customer record into CRM
Click buttonsSubmit form or download report
Make rule-based decisionsIf invoice amount is above limit, send for approval
Send notificationsEmail manager after task completion
Input
Excel File
Email Attachment
Web Form
Bot Workflow
Read Data
Validate Rules
Enter System
Generate Report
Output
Updated ERP
Email Sent
Report Saved

5.4 Bot Development Lifecycle

Bot development should follow a structured lifecycle to ensure that the bot is reliable, secure and useful.

StageDescriptionDeliverable
Process UnderstandingStudy the manual process and business rules.Process map
Requirement DocumentationDefine input, output, systems, exceptions and success criteria.Process design document
Bot DesignPlan bot steps, logic, variables and decision points.Bot workflow diagram
Bot DevelopmentBuild automation using RPA tool or script.Working bot
TestingTest with normal and exception cases.Test report
DeploymentMove bot to production environment.Live automation
MonitoringTrack 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

Read Invoice Amount

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_email

5.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 NameData TypeExample ValueUse
invoice_numberTextINV-10025Identify invoice
invoice_amountNumber3500Check approval rule
is_approvedBooleanTrueDecision making
customer_emailTextcustomer@email.comSend notification
process_dateDate2026-06-02Record processing date
Good Practice: Use clear variable names. For example, use invoice_amount instead of x.

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 IDNameStatusBot Action
C001AminActiveUpdate CRM
C002Mei LingInactiveSkip or flag
C003RaviActiveUpdate CRM
for each row in customer_table:
    read customer_id
    read status

    if status == "Active":
        update_crm_record
    else:
        add_to_exception_report

5.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 ElementBot ActionExample
Text BoxType dataEnter customer name
ButtonClickClick Submit
DropdownSelect optionSelect department
TableRead rowsExtract invoice list
Web LinkNavigateOpen report page
Common Problem: Bots fail when UI elements change. For example, a button name, screen layout or website structure may change.

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.")
Expected Result:
All Excel files in the reports folder are renamed with PDTC_ prefix.

Line-by-Line Explanation

CodeExplanation
import osImports 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.

1Open Mailbox
2Read Unread Emails
3Download Attachments
4Process Data
5Send Reply

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 folder

5.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 TypeExampleHandling Method
Missing FileExcel file not foundLog error and notify user
Invalid DataInvoice amount is blankAdd record to exception report
Login FailurePassword expiredStop process and alert admin
System TimeoutERP page not loadingRetry after waiting
Selector FailureSubmit button not foundUse fallback selector or raise exception

Try-Except Concept

try:
    open_excel_file
    read_invoice_data
    update_erp_system

except:
    log_error
    send_alert_email

5.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 FieldExample
Bot NameInvoice Processing Bot
Start Time08:00 AM
End Time08:15 AM
Records Processed120
Successful Records115
Exception Records5
StatusCompleted with exceptions
Audit Importance: Logs support compliance, troubleshooting, performance measurement and process improvement.

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

1Read Excel
2Validate Data
3Open System
4Enter Invoice
5Update Log

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_email

5.14 Best Practices for Bot Development

Best PracticeReason
Use clear namingMakes workflow easier to understand.
Break large process into smaller stepsImproves maintenance and testing.
Validate input dataPrevents wrong processing.
Add exception handlingPrevents bot failure from stopping entire process.
Create logsSupports audit and troubleshooting.
Test with real scenariosImproves reliability.
Protect credentialsImproves 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.

Instructions: Select the correct answer for each question and click Submit Assessment.

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.

Remember: A good bot is not only a sequence of clicks. It must be well designed, properly tested, secure, maintainable and able to handle exceptions.