How to use the Selenium Java Code Generator
- 1. Write the stepsOne per line: open a page, type, click, select, and check URL, text or visibility.
- 2. Choose the setupFramework, browser, headless mode, package, class name and wait time.
- 3. GenerateCopy the Java class and the pom.xml dependencies into your project.
What the code looks like
You describe the test in plain lines, one action per line: open /login, type label=Email = asha@example.com, click role=button[name=Log in], then checks such as expect url /dashboard or expect visible testid=logout. Selectors can be CSS, or text=, label=, placeholder=, testid= and role=, which survive design changes better than long CSS paths. Everything runs in your browser; nothing you enter is uploaded.
The generated class uses Selenium 4's WebDriverWait with ExpectedConditions for every action, so it waits for elements instead of using fixed sleeps. Each selector becomes a named By field, such as emailField, which reads like a lightweight page object. text= and label= selectors become XPath, with quotes handled safely. Drivers are downloaded automatically by Selenium Manager, so there's no WebDriverManager or driver path to set up.
Worked example
The sample steps log a student in and out. With TestNG and Chrome, the tool writes a 56-line LoginTest class with four locators (emailField, passwordField, logIn and logout), a @BeforeMethod that starts Chrome with a 10-second wait, one @Test method and a @AfterMethod that quits the browser. The class compiles cleanly with javac -Xlint:all -Werror against the Selenium and TestNG method signatures it uses.
Next steps
- As the suite grows, move locators and actions into page classes and keep tests short.
- Use
data-testidattributes in your app for selectors that don't change with the design. - The pom.xml versions are editable; check Maven Central for the latest before you start.
Frequently asked questions
Do I need ChromeDriver?
No. Since Selenium 4.6, Selenium Manager finds or downloads the right driver automatically.
Can I run it in CI?
Yes. Tick Headless, and run with mvn test on a machine with the browser installed.
Is the Selenium Java code generator free?
Yes. You can open the Selenium Java code generator and fill in everything without signing up. When you generate code for the first time, we ask once for your name and WhatsApp number; after that it, and every other Uncodemy tool, opens straight away.