Problem
Repetitive data entry takes time, causes fatigue and increases the chance of manual errors when it has to be done row by row.
technical case study
Automation • RPA / Automated data entry
Python desktop automation that registers products in bulk from a CSV spreadsheet, controlling the browser with PyAutoGUI.
Demo site included in the repository: the bot opens the browser in a dedicated window and logs in before registering.
produtos.csv with 293 products (code, brand, type, category, price, cost and notes), validated with Pandas before starting.
Row-by-row entry using the keyboard (Tab and Enter); each submission only counts once it is confirmed by the window title.
Repetitive data entry takes time, causes fatigue and increases the chance of manual errors when it has to be done row by row.
A Python script was created that reads products from a CSV and automates the browser, filling in fields and submitting entries in sequence.
The automation turned a repetitive manual task into a runnable workflow, reducing effort and creating a base for other RPA routines.
Version 1.0.3 published on GitHub as AutoTask Bot, configurable through config.json; next steps include logs and a control interface.
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.
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.
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.
CSV file with products and attributes used as input to fill in the form automatically.
Login values can come from environment variables; real credentials are not kept in config.json or in the repository.
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.
PyAutoGUI's FAILSAFE to stop at any time, a lock against two simultaneous runs and an automatic stop if a submission isn't confirmed.
Identifying the manual steps needed to open the system, log in and reach the form.
Using Pandas to load the products and turn each row into a set of fields.
Typing and Tab to fill in the form field by field, in the order defined in config.json.
Repeating the workflow for every product listed in the CSV.
Evolving into AutoTask Bot: JSON configuration, CSV validation, confirmation of each submission and its own demo site.
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
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, "")
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)
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)),
)
The automation reduced a repetitive data entry routine to a runnable script, creating a reusable base for other operational tasks.
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.