Guozhen AIGlobal AI field notes and model intelligence

English translation

Wait 5 seconds — give user time to switch to the target webpage

Published:

Category: App Automation

Read time: 3 min

Reads: 0

Lesson #19Views are counted together with the original Chinese articleImages are preserved from the source page

AI Article Decision Snapshot

Turn the lesson into workflow, model, budget, and security checks before choosing tools.

Use this quick snapshot before leaving the article. It keeps the next search tied to practical AI software, model/API, cost, privacy, and implementation questions.

Workflow fit

Identify the real job behind the article: coding, research, document review, support, analytics, content, or internal automation.

Model or tool decision

Decide whether the next step is a software shortlist, an AI tool comparison, an API platform choice, or a model benchmark.

Budget and usage signal

Estimate seats, API calls, prompt volume, retries, review time, and fallback work before assuming the workflow is cheap.

Security and privacy review

Check whether source code, customer data, private documents, prompts, logs, or embeddings will enter the AI workflow.

In the previous article, we explored desktop application automation using PyAutoGUI, focusing on image recognition and interaction—learning how to leverage visual pattern matching to automate routine tasks. In this tutorial, we’ll dive into a practical use case: automating website login—demonstrating how to perform software automation with Python.

Use Case Background

In daily work, many people must log in to websites repeatedly—a task that quickly becomes tedious. This is especially true when logging into the same site multiple times throughout the day; manually entering usernames and passwords grows increasingly monotonous. Automating such tasks saves time and significantly boosts productivity.

Tool Selection

For this case, we’ll use the following tools:

  1. PyAutoGUI: To execute GUI-level automation actions (e.g., mouse clicks, keyboard input).
  2. time module: To introduce deliberate delays between operations.
  3. A web browser: For testing the login flow.

Step Overview

  1. Environment Setup: Ensure PyAutoGUI is installed.
  2. Locate Web Page Elements: Use a screenshot tool to identify screen coordinates of key UI elements (e.g., username field, password field, login button).
  3. Write the Automation Script: Develop a Python script that launches the browser and performs the full login sequence.

1. Environment Setup

Install the PyAutoGUI library in your Python environment using the following command:

pip install pyautogui

2. Locate Web Page Element Coordinates

First, capture a screenshot of the target login page (e.g., using Windows Snipping Tool or macOS Screenshot utility), then identify and record the screen coordinates of the following elements:

  • Username input field
  • Password input field
  • Login button

We recommend marking these positions directly on the screenshot for accuracy.

For example, suppose your annotated coordinates are:

  • Username field: (500, 400)
  • Password field: (500, 450)
  • Login button: (500, 500)

⚠️ Note: These coordinates are absolute screen coordinates—they depend on your display resolution and browser window position. Always verify them before running the script.

3. Write the Automation Script

Below is a simple Python script that uses PyAutoGUI to automate the login process:

import pyautogui
import time

# Wait 5 seconds — give user time to switch to the target webpage
print("Please switch to the target webpage within 5 seconds...")
time.sleep(5)

# Define credentials
username = 'your_username'
password = 'your_password'

# Enter username
pyautogui.click(500, 400)  # Click username field
pyautogui.typewrite(username, interval=0.1)  # Type username slowly

# Enter password
pyautogui.click(500, 450)  # Click password field
pyautogui.typewrite(password, interval=0.1)  # Type password slowly

# Click login button
pyautogui.click(500, 500)  # Click login button

print("Automatic login completed!")

Code Breakdown

  • time.sleep(5): Pauses execution for 5 seconds—giving you time to manually navigate to and focus the target webpage.
  • pyautogui.click(x, y): Moves the mouse to screen coordinates (x, y) and performs a left-click.
  • pyautogui.typewrite(text, interval): Types the given string character-by-character, with interval (in seconds) controlling the delay between keystrokes—helping avoid race conditions caused by slow page rendering.

Troubleshooting Common Issues

  1. Inaccurate Coordinates: Double-check that your recorded coordinates match the actual positions of elements at runtime. Adjust values iteratively if needed—consider using pyautogui.position() to print current mouse coordinates during debugging.
  2. Too-Fast Execution: If text appears incomplete or buttons are missed, increase the interval in typewrite() or add extra time.sleep() calls before critical actions (e.g., after page load). You may also use pyautogui.PAUSE = 0.5 globally to add default delays between all PyAutoGUI actions.

Summary

In this tutorial, we demonstrated how to automate a website login using Python and PyAutoGUI. By combining precise screen coordinate targeting with timed input simulation, we built a lightweight yet effective automation solution for repetitive GUI tasks.

Such automation not only reduces manual effort but also minimizes human error—making workflows more reliable and scalable.

In the next tutorial, we’ll explore another real-world scenario: automating batch data processing. Stay tuned!

Apply This Lesson

Turn this article into AI software, model, API, and security decisions.

English Article FAQ

Use this article as evidence before choosing AI tools

How should I use this AI Tutorials article?

Use it as the implementation or learning layer, then connect the idea to AI software buyer guides, tool comparisons, benchmarks, API choices, and security checks before making a production decision.

Is this English article different from the Chinese original?

The English edition is localized for global AI readers while preserving the original diagrams, screenshots, prompts, code examples, and source context from the Chinese article.

What should I read after Wait 5 seconds — give user time to switch to the target webpage?

Continue with AI Software Buyer Guides, AI Tools Workbench, Best AI Coding Agents, AI Model Benchmarks, OpenAI vs Anthropic API, or LLM Security Tools depending on the decision you need to make.

Can this article alone choose an AI product or model?

No. Treat the article as evidence and context, then validate fit with pricing, privacy requirements, integration effort, benchmark results, workflow tests, and fallback planning.

Continue

Keep reading from here

Browse English site

Reader Messages

Reader messages

Questions, corrections, extra sources, or hands-on results can be left here. No login is required.

Max 800 characters

To reduce spam, each message is checked for length, link count, and posting frequency.

0/800

Messages

0 messages
Loading messages...