technical case study

Automation • RPA / Automated data entry

RPA Automated Data Entry

Python desktop automation that registers products in bulk from a CSV spreadsheet, controlling the browser with PyAutoGUI.

Automation, operational workflow and scripting Completed Automation completed
Python PyAutoGUI Pandas CSV RPA
executive summary

Problem

Repetitive data entry takes time, causes fatigue and increases the chance of manual errors when it has to be done row by row.

Solution

A Python script was created that reads products from a CSV and automates the browser, filling in fields and submitting entries in sequence.

Result

The automation turned a repetitive manual task into a runnable workflow, reducing effort and creating a base for other RPA routines.

Current stage

Version 1.0.3 published on GitHub as AutoTask Bot, configurable through config.json; next steps include logs and a control interface.

context

Automating repetitive tasks without a formal integration

The project explores a practical RPA approach: controlling the browser interface when there is no API, or when the goal is to automate a process exactly as a person would. The current version, AutoTask Bot, evolved from a 2023 study script: the workflow is now configured in a JSON file and navigation relies on field focus and the Tab key, without fixed screen coordinates.

goals and constraints

Goals

  • Open the browser and go to the system page
  • Log in to the data entry environment
  • Read products from a CSV spreadsheet
  • Fill in form fields automatically
  • Repeat the entry for every row in the file

Constraints

  • Works with forms that support keyboard navigation; CAPTCHAs, iframes and custom components may prevent its use
  • The browser must stay visible, and mouse and keyboard are busy while it runs
  • Title-based confirmation depends on a predictable window title
  • Less robust than an API integration
solution architecture

Front-end

PyAutoGUI drives the browser with keyboard and mouse (typing, Tab and submit) in a dedicated Chromium window with its own profile to avoid pop-ups and extra tabs.

Back-end

bot.py reads the rules from config.json (URL, login, fields, submit and confirmation), validates the CSV with Pandas, opens the browser and goes through each record, confirming every submission before the next.

Database

CSV file with products and attributes used as input to fill in the form automatically.

security and safeguards

Credentials outside the code

Login values can come from environment variables; real credentials are not kept in config.json or in the repository.

No fixed coordinates

Navigation uses field focus and the Tab key. When a click is needed, the position is calibrated as a proportion of the window, not absolute pixels.

Supervised execution

PyAutoGUI's FAILSAFE to stop at any time, a lock against two simultaneous runs and an automatic stop if a submission isn't confirmed.

process
01

Mapping the workflow

Identifying the manual steps needed to open the system, log in and reach the form.

02

Reading the spreadsheet

Using Pandas to load the products and turn each row into a set of fields.

03

Automating input

Typing and Tab to fill in the form field by field, in the order defined in config.json.

04

Entry loop

Repeating the workflow for every product listed in the CSV.

05

Configurable version

Evolving into AutoTask Bot: JSON configuration, CSV validation, confirmation of each submission and its own demo site.

behind the scenes
bot.py Python lines 214–248
def load_rows(config: dict[str, Any], limit: int | None = None) -> pd.DataFrame:
    data_config = config["data"]
    csv_path = resolve_project_path(data_config["csv_path"])

    if not csv_path.is_file():
        raise FileNotFoundError(f"Arquivo CSV não encontrado: {csv_path}")

    products = pd.read_csv(csv_path, dtype="string")
    required_columns = set(data_config.get("required_columns", []))
    required_columns.update(
        field["name"]
        for field in config["form"]["fields"]
        if field.get("source") == "column"
    )

    missing = required_columns - set(products.columns)
    if missing:
        missing_text = ", ".join(sorted(missing))
        raise ValueError(f"O CSV não possui as colunas obrigatórias: {missing_text}")

    non_empty_columns = set(data_config.get("non_empty_columns", []))
    if non_empty_columns:
        invalid_rows = products[list(non_empty_columns)].isna().any(axis=1)
        if invalid_rows.any():
            rows = ", ".join(
                str(index + 2) for index in products.index[invalid_rows][:10]
            )
            raise ValueError(f"Valores obrigatórios vazios nas linhas do CSV: {rows}")

    if limit is not None:
        if limit <= 0:
            raise ValueError("O valor de --limit precisa ser maior que zero.")
        products = products.head(limit)

    return products
Reads the CSV with Pandas and validates it before starting: required columns present and no required field empty.
bot.py Python lines 851–886
def perform_login(config: dict[str, Any]) -> None:
    login = config.get("login", {})
    if not login.get("enabled", False):
        return

    browser = config["browser"]
    login_title = str(
        login.get(
            "window_title_contains",
            browser.get("ready_title_contains", ""),
        )
    ).strip()
    if login_title:
        ensure_target_window(login_title, float(browser.get("window_timeout_seconds", 15)))

    time.sleep(float(config["automation"].get("focus_settle_seconds", 0.2)))
    focus_first_field(login["focus"])
    fill_fields(
        fields=login.get("fields", []),
        row=None,
        empty_values={},
        write_interval=float(config["automation"].get("write_interval", 0.01)),
    )
    perform_submit(login.get("submit", {"method": "key", "key": "enter"}))

    success_title = str(login.get("success_title_contains", "")).strip()
    if success_title:
        wait_for_window(
            success_title,
            float(login.get("success_timeout_seconds", 8.0)),
            activate=True,
        )
        dismiss_post_login_prompts(browser, success_title)
    else:
        time.sleep(float(login.get("after_submit_wait_seconds", 1.0)))
        dismiss_post_login_prompts(browser, "")
Waits for the right window, fills in the login defined in config.json and only continues when the products page shows up in the title.
bot.py Python lines 744–789
def resolve_field_value(
    field: dict[str, Any],
    row: pd.Series | None,
    empty_values: dict[str, str],
) -> str:
    source = field.get("source", "column")

    if source == "column":
        if row is None:
            raise ValueError("Um campo de coluna foi usado sem uma linha do CSV.")
        name = field["name"]
        value = row[name]
        fallback = field.get("empty", empty_values.get(name, ""))
        if pd.isna(value) or not str(value).strip():
            return str(fallback)
        return str(value)

    if source == "literal":
        return str(field.get("value", ""))

    if source == "env":
        name = field["name"]
        value = os.getenv(name)
        if value is None:
            raise ValueError(f"A variável de ambiente '{name}' não foi definida.")
        return value

    raise ValueError(f"Fonte de campo não suportada: {source}")


def fill_fields(
    fields: list[dict[str, Any]],
    row: pd.Series | None,
    empty_values: dict[str, str],
    write_interval: float,
) -> None:
    for field in fields:
        value = resolve_field_value(field, row, empty_values)
        if field.get("clear", True):
            clear_and_write(value, write_interval)
        else:
            pa.write(value, interval=write_interval)

        tabs_after = int(field.get("tabs_after", 1))
        if tabs_after:
            pa.press("tab", presses=tabs_after, interval=0.03)
Each field comes from the CSV, a fixed text or an environment variable and is filled with typing and Tab, without fixed coordinates.
bot.py Python lines 889–922
def fill_form_row(config: dict[str, Any], row: pd.Series) -> None:
    form = config["form"]
    expected_title = str(form.get("window_title_contains", "")).strip()

    if expected_title:
        window = ensure_target_window(
            expected_title,
            float(form.get("window_timeout_seconds", 4.0)),
        )
        previous_title = str(window.title)
    else:
        try:
            window = pa.getActiveWindow()
            previous_title = str(window.title if window else "")
        except (AttributeError, NotImplementedError):
            previous_title = ""

    time.sleep(float(config["automation"].get("focus_settle_seconds", 0.2)))
    focus_first_field(form["focus"])
    fill_fields(
        fields=form["fields"],
        row=row,
        empty_values=config["data"].get("empty_values", {}),
        write_interval=float(config["automation"].get("write_interval", 0.01)),
    )
    perform_submit(form.get("submit", {"method": "key", "key": "enter"}))

    confirmation = form.get("confirmation", {"method": "wait"})
    confirm_form_submission(
        confirmation,
        previous_title,
        expected_title,
        float(form.get("after_submit_wait_seconds", 0.3)),
    )
Fills in and submits one CSV row and waits for the submission to be confirmed before moving to the next.
impact

Results

The automation reduced a repetitive data entry routine to a runnable script, creating a reusable base for other operational tasks.

Learnings

The main lesson was balancing practicality and robustness: screen-based automations are quick to build, but need environment control, logs and failure handling for more serious use.