DEV Community

Zain Ul Rehman
Zain Ul Rehman

Posted on

ChatGPT Prompts for Selenium Tests: A Practical Starter Set

A good prompt for Selenium work states the language, the framework, the page under test and what you want back. A vague prompt gets vague code.

This is a short version of my full guide with the complete prompt list, common mistakes and a workflow section: ChatGPT Prompts for Selenium Tests.

What makes a prompt work

  1. Name the stack: language, Selenium version, test runner.
  2. Paste the real HTML or locators instead of describing the page.
  3. Say what the output should look like (one class, one test, comments or none).
  4. Ask for one thing at a time.

Categories covered in the full guide

  • Setting up Selenium
  • Page Object Model
  • Writing test cases
  • Debugging and fixing tests
  • CI/CD and framework tasks

Example prompt (a template, adapt it to your project)

Write a Page Object class in Java for the login page below, using Selenium 4 and explicit waits. Include methods for entering a username, a password and clicking Log in. HTML: [paste the form HTML here]

Always review the output

Generated code can use outdated methods, invented locators or waits that make tests flaky. Run it, read it and fix it before it goes near your suite. ChatGPT is a fast first draft, not a replacement for knowing Selenium.

Full prompt list: https://aitestingguide.com/chatgpt-prompts-for-selenium-tests/

Top comments (0)