If you have ever stared at a blank test file wondering how to start, ChatGPT prompts for Selenium tests can change your workflow completely. In 2026, the best SDETs are not writing every line of automation code from scratch — they are using AI to accelerate test creation while applying their expertise to review and improve the output.
In this guide, I will share the exact ChatGPT prompts for Selenium tests that I use in my own workflow, explain how to get the best results from each one, and show you how to integrate AI-assisted test writing into your daily automation practice.
Table of Contents
Why Use ChatGPT for Selenium Tests?
Before diving into the prompts, it helps to understand what ChatGPT is genuinely good at in a test automation context — and where its limitations are.
ChatGPT is excellent at generating boilerplate code, scaffolding test structures, suggesting locator strategies, and writing repetitive test variations quickly. A task that might take you 30 minutes to write from scratch can be drafted in 2 minutes with the right prompt.
ChatGPT is not a replacement for SDET expertise. It does not know your application, it cannot run the tests it writes, and it sometimes generates code that looks correct but contains subtle errors. Your job as an SDET is to prompt effectively, review critically, and refine intelligently.
Think of ChatGPT as a junior developer on your team — fast, enthusiastic, and capable, but always needing review before the code goes anywhere important.
How to Get the Best Results from ChatGPT Prompts
Before sharing the prompts, here are four rules that dramatically improve the quality of ChatGPT output for test automation:
Be specific about your stack. Always mention Python or Java, Selenium 4, Pytest or TestNG, and any specific patterns like Page Object Model. Vague prompts produce generic code that needs heavy editing.
Provide context about the application. Tell ChatGPT what the page does, what elements are involved, and what the expected behavior is. The more context you give, the more accurate the output.
Ask for one thing at a time. Do not ask ChatGPT to write an entire framework in one prompt. Break it down — one page class, one test file, one utility function at a time.
Always review and test the output. Never paste ChatGPT code directly into production without running it and understanding every line. This is non-negotiable.
ChatGPT Prompts for Selenium Tests — By Category
Prompts for Setting Up Selenium
Prompt 1 — Basic Selenium Setup
Use this when starting a new project and need the initial browser configuration.
Prompt to use:
Write a Python function that sets up a Chrome browser using Selenium 4 with the following options: headless mode disabled, window size 1920x1080, implicit wait of 10 seconds. Use the webdriver-manager library to handle ChromeDriver automatically. Include all necessary imports.What this gives you: A clean, ready-to-use browser setup function that handles driver management automatically. Copy this into your conftest.py as a Pytest fixture.
Prompt 2 — Cross-Browser Setup
Use this when you need tests to run on multiple browsers.
Prompt to use:
Write a Pytest fixture in Python that accepts a browser parameter and returns a Selenium WebDriver instance for Chrome, Firefox, or Edge based on the parameter value. Use webdriver-manager for driver management. Include error handling for unsupported browser names.What this gives you: A parametrized browser fixture that lets you run the same tests across multiple browsers by changing a single parameter.
Prompts for Page Object Model
Prompt 3 — Login Page Class
Use this when building your first POM page class.
Prompt to use:
Write a Python Page Object Model class for a login page using Selenium 4. The page has a username field with id "username", a password field with id "password", and a submit button with id "login-button". Include methods for entering username, entering password, clicking submit, and getting the error message text. Use explicit waits with WebDriverWait. Follow POM best practices.What this gives you: A complete, well-structured login page class with proper explicit waits and clean method names. Adapt the locators to match your actual application.
Prompt 4 — Dashboard Page Class
Use this after the login page to build the next page in your flow.
Prompt to use:
Write a Python Page Object Model class for a dashboard page using Selenium 4. The page has a welcome message with class "welcome-header", a navigation menu with id "main-nav", and a logout button with class "logout-btn". Include methods for getting the welcome message text, clicking a navigation item by name, and clicking logout. Use explicit waits throughout.What this gives you: A dashboard page class that pairs with the login page class to build a complete end-to-end flow.
Prompt 5 — Search Page Class
Use this for any page with search functionality.
Prompt to use:
Write a Python Page Object Model class for a search page using Selenium 4. The page has a search input with name "q", a search button with class "search-btn", and search results displayed in a list with class "results-list". Include methods for entering a search term, submitting the search, getting the number of results, and getting the text of a result by index. Use explicit waits.Prompts for Writing Test Cases
Prompt 6 — Login Test Cases
Use this to generate a complete set of login test scenarios.
Prompt to use:
Write Pytest test cases in Python for a login page using Selenium 4 and the Page Object Model. Import LoginPage from pages.login_page. Write tests for: successful login with valid credentials, failed login with invalid password, failed login with empty username, failed login with empty password, and successful logout after login. Use Pytest fixtures for browser setup and teardown. Include assertions for each scenario.What this gives you: Five complete test cases covering the most important login scenarios. This is the kind of coverage that impresses hiring managers in SDET interviews.
Prompt 7 — Data Driven Test Cases
Use this when you need to test the same scenario with multiple data sets.
Prompt to use:
Write a data-driven Pytest test in Python using Selenium 4 that tests a login form with multiple username and password combinations. Use pytest.mark.parametrize to run the test with the following combinations: valid username and valid password should succeed, valid username and wrong password should fail, empty username and valid password should fail. Import LoginPage from pages.login_page.What this gives you: A parametrized test that runs three scenarios in one clean test function — the standard way to handle data-driven testing in Pytest.
Prompt 8 — API and UI Combined Test
Use this for end-to-end tests that combine API setup with UI verification.
Prompt to use:
Write a Pytest test in Python that first creates a test user via a POST request to https://reqres.in/api/users using the Requests library, then uses Selenium 4 to navigate to a login page and verify the user can log in. Include proper setup, teardown, and assertions for both the API response and the UI behavior.What this gives you: A hybrid test that demonstrates end-to-end thinking — exactly the kind of test that differentiates strong SDET candidates.
Prompts for Debugging and Fixing Tests
Prompt 9 — Debugging a Flaky Test
Use this when a test fails intermittently, and you cannot identify the cause.
Prompt to use:
I have a Selenium test in Python that intermittently fails with a StaleElementReferenceException on this line: [paste your failing line here]. The test clicks a button that triggers a page reload. Explain why this exception occurs and rewrite the code to handle it correctly using explicit waits.What this gives you: A clear explanation of the root cause plus corrected code. Understanding why the fix works is as important as the fix itself.
Prompt 10 — Converting XPath to CSS Selectors
Use this when you have brittle XPath expressions that break frequently.
Prompt to use:
Convert these XPath selectors to CSS selectors for use in Selenium 4. Explain why each CSS selector is more reliable than the XPath equivalent: [paste your XPath selectors here].What this gives you: More stable locators plus an explanation that helps you write better locators independently in the future.
Prompts for CI/CD and Framework Tasks
Prompt 11 — Pytest Configuration File
Use this when setting up a new project and need a standard configuration.
Prompt to use:
Write a pytest.ini configuration file for a Selenium test project in Python. Include configuration for: test discovery pattern, default command line options to show test output verbosely, HTML report generation using pytest-html, and markers for smoke, regression, and sanity test categories.What this gives you: A complete pytest.ini that makes your project feel professional and well-configured from day one.
Prompt 12 — GitHub Actions Workflow
Use this when setting up CI/CD for your automation project.
Prompt to use:
Write a GitHub Actions workflow file that runs a Python Selenium test suite on every push to the main branch. The workflow should: use Ubuntu latest, install Python 3.11, install dependencies from requirements.txt, install Chrome browser, run pytest with HTML report generation, and upload the HTML report as a workflow artifact.What this gives you: A complete CI/CD pipeline that runs your tests automatically in the cloud on every code push.
You can learn more about setting up workflows at the GitHub Actions documentation.
How to Use These Prompts Effectively
Step 1 — Start with the setup prompts. Get your browser configuration and project structure right before writing any tests. A solid foundation saves hours of debugging later.
Step 2 — Build page classes before test cases. Always write your POM classes first and verify the locators work before asking ChatGPT to write tests that use those classes.
Step 3 — Review every line of generated code. Read the code ChatGPT produces line by line. If you do not understand a line, ask ChatGPT to explain it. You are responsible for every line in your repository.
Step 4 — Iterate on the prompt. If the first output is not quite right, do not start over. Tell ChatGPT what is wrong and ask it to fix the specific issue. Iterative refinement produces much better results than starting fresh.
Step 5 — Test the code immediately. Run every generated snippet as soon as you copy it. Catching errors early prevents them from compounding as you build more code on top.
Common Mistakes When Using ChatGPT Prompts for Selenium Tests
Using generated code without understanding it. This is the most dangerous mistake. If you cannot explain every line in your test to an interviewer, you do not own that code.
Accepting the first output without refinement. ChatGPT’s first response is a starting point, not a finished product. The best results come from two to three rounds of refinement.
Asking for too much at once. Prompts that ask for an entire framework in one go produce messy, inconsistent code. Small, focused prompts produce clean, maintainable output.
Not providing locator information. Generic prompts produce generic locators like By.ID “submit” that will not work in your actual application. Always provide real element information from your application.
Integrating ChatGPT into Your SDET Workflow
The most effective way to use ChatGPT prompts for Selenium tests in a professional SDET workflow is not to replace your coding — it is to eliminate the parts of coding that are repetitive and time-consuming so you can focus on the parts that require real expertise.
Use ChatGPT for first drafts of page classes, boilerplate test structures, configuration files, and CI/CD pipelines. Use your own expertise for framework architecture decisions, locator strategy, test coverage planning, and code review.
This combination — AI speed plus SDET expertise — is what separates productive modern SDETs from engineers who either avoid AI entirely or use it without critical judgment.
If you are still building your Selenium foundation, read my guide on how to become an SDET in 2026 before diving deep into AI-assisted test writing. And for a broader look at AI tools in the testing space, read my review of the best AI testing tools for QA engineers.
Final Thoughts
ChatGPT prompts for Selenium tests are one of the most practical productivity tools available to SDETs in 2026. Used correctly, they accelerate test creation, reduce boilerplate fatigue, and help you learn new patterns faster.
Used incorrectly — copying code you do not understand, skipping review, or relying on AI for architecture decisions — they create technical debt and interview embarrassment.
The prompts in this guide are starting points. Adapt them to your specific application, refine the output, and always understand what you are committing to your repository.
The best SDETs in 2026 are not the ones who avoid AI or the ones who blindly trust it. They are the ones who use it as a skilled tool — knowing when to use it, how to direct it, and when to override it.
Frequently Asked Questions
Can ChatGPT write production-ready Selenium tests?
Not directly. ChatGPT can write tests that are a strong starting point, but they always require review, locator verification, and testing against your actual application before they are production-ready.
Which version of ChatGPT works best for writing Selenium tests?
GPT-4 produces significantly better code quality than GPT-3.5 for test automation tasks. The improved reasoning ability results in better locator strategies, more robust wait handling, and cleaner code structure.
Can I use these prompts with other AI tools like GitHub Copilot?
Yes — the prompt principles apply to any AI coding assistant. GitHub Copilot works inline in your IDE and is particularly useful for completing page class methods as you type. The same rules apply — review everything it generates.
Do I need to know Selenium before using ChatGPT for test generation?
Yes — you need enough Selenium knowledge to review and correct the generated code. If you do not understand Selenium fundamentals, you cannot identify when ChatGPT makes mistakes. Read my SDET interview questions guide to assess your current Selenium knowledge level.

