How to Use Selenium 2 with Maven
Add Selenium 2 to a Maven project, run a local browser test, and troubleshoot common setup errors. Includes the historical version caveat.
Selenium 2 works in a Maven project by adding the Java client dependency org.seleniumhq.selenium:selenium-java:2.53.1 to the <dependencies> section of pom.xml. Version 2.53.1 is a historical release from June 30, 2016. If you are maintaining a project that needs Selenium 2, pin that version; for a new project, follow the current Selenium Java installation guide and choose a current release.
1. Add the Selenium 2 dependency
Create a Maven project or open its existing pom.xml. Add the dependency inside the top-level <dependencies> element:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>selenium2-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<selenium.version>2.53.1</selenium.version>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
</project>
The property keeps the version in one place; it is a Maven convenience, not a Selenium requirement. You can instead write <version>2.53.1</version> directly. The coordinates are published in Maven Central. The Selenium Java artifact also brings in Selenium support and browser-specific driver modules.
2. Write and run a minimal Java browser test
For Selenium 2, a local browser driver generally needs the matching browser driver executable installed and discoverable by the operating system. This example uses Firefox and the Selenium 2-era FirefoxDriver API. Save it as src/main/java/example/TitleCheck.java:
package example;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TitleCheck {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
try {
driver.get("https://example.com");
System.out.println("Title: " + driver.getTitle());
} finally {
driver.quit();
}
}
}
Compile the project and resolve its dependencies with mvn compile. To execute a plain main method, use an IDE or configure a Maven execution plugin in your project; Maven does not automatically run arbitrary main classes as tests. For an automated test suite, place test code under src/test/java, add a test framework such as JUnit, and run it with mvn test.
The exact local driver setup depends on the browser and Selenium 2 API in use. Selenium 2 predates the current Selenium Manager workflow, so do not assume a current Selenium tutorial’s automatic driver management instructions apply. Consult the Selenium downloads archive for historical distributions and driver references.
3. Choose the right Selenium artifact
| Need | Maven artifact | When to use it |
|---|---|---|
| Java WebDriver client for local browser automation | org.seleniumhq.selenium:selenium-java:2.53.1 |
Typical Selenium 2 Java project. |
| Selenium Server for a remote execution arrangement | org.seleniumhq.selenium:selenium-server:2.53.1 |
Only when your setup uses a remote server or Grid. The server is a separate artifact; it is not required for ordinary local WebDriver use. |
Keep the version aligned across any Selenium components you declare directly. The existence of the server artifact does not by itself configure a Grid; server deployment and remote capabilities are a separate setup.
4. Keep the legacy version or move to current Selenium?
The archive dates Selenium 2.53.1 to June 30, 2016. Keep it when you need compatibility with an existing codebase or a Selenium 2 API. For a new project, check the current installation documentation instead of copying the historic pin. Compare the existing Java runtime, browser environment, API usage, and local versus remote execution needs before upgrading; the available sources do not provide a complete compatibility matrix.
Current Selenium documentation uses the same general Maven approach—declare selenium-java in the POM—but the release version and surrounding setup have moved on. Avoid mixing version numbers across Selenium artifacts, and make upgrades as an intentional change with your project’s browser tests.
5. Troubleshooting
| Symptom | Likely cause | What to check |
|---|---|---|
Could not find artifact or dependency resolution failure |
Typo in group, artifact, or version, or Maven cannot reach its repository. | Use the exact coordinates above, check network/proxy settings, and retry with mvn -U compile. |
package org.openqa.selenium does not exist |
The dependency is outside <dependencies>, the POM is not the one being built, or dependencies were not imported. |
Check the active project directory and POM, then run mvn dependency:tree and refresh the IDE’s Maven project. |
| Driver executable not found | The browser driver is absent or not on the process PATH. | Install the driver appropriate to the browser and environment, verify its executable permissions and PATH, and follow documentation for the Selenium 2 API you use. |
| Browser and driver fail to start together | Driver/browser mismatch, unsupported environment, or an incompatible legacy runtime. | Check the browser and driver versions and the Selenium 2 release archive. Avoid assuming a modern driver-management feature exists in Selenium 2. |
| Browser opens but the test hangs or leaves processes behind | Navigation may be waiting, an exception bypassed cleanup, or the browser session is not closed. | Put work in try/finally and always call driver.quit(). Set appropriate page-load or script timeouts if supported by the API you use. |
mvn test reports no tests |
A main class is not a test, or test framework/dependency and naming conventions are missing. | Put tests under src/test/java, add and configure the chosen test framework, and follow its Maven test naming conventions. |
6. Performance, reliability, and cost
- Dependency resolution: Maven downloads the Selenium artifact and its transitive modules on the first build; later builds use the local repository unless dependencies change or are refreshed.
- Test runtime: Starting a real browser is usually the costly step in a small test. Reuse a driver within a test where appropriate, and close it reliably with
quit(). - Reproducibility: Pinning
2.53.1makes the dependency version explicit. Keep browser and driver setup documented alongside it, since the dependency alone does not install every external browser executable. - Maintenance: Selenium 2.53.1 is historical. Legacy constraints can be valid, but new projects should evaluate current Selenium rather than treating the old version as the default.
- Cost: The Maven dependency is software retrieved from a repository; browser execution consumes your own machine or CI resources. No hosted execution price follows from this Maven declaration.
7. Or skip the browser setup
If the task is to capture a page image rather than interact with it as a browser test, ScreenshotNeo provides a website screenshot API and MCP server. See the API documentation. One GET request returns an image or PDF:
curl -G "https://api.screenshotneo.com/v1/shot" \
-d access_key=YOUR_API_KEY \
--data-urlencode url=https://example.com \
-o shot.webp
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://example.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://example.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed; response headers identify the page verdict and billing status. Its MCP server lets AI agents use screenshot, page-info, and PDF tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.
FAQ
Is Selenium 2.53.1 the current Selenium version?
No. It is a historical release dated June 30, 2016. Use it for a specific legacy need; consult current Selenium documentation for a new project.
Does adding selenium-java install Firefox or Chrome?
No. Maven resolves Java libraries. The browser and the matching driver setup are separate environment requirements.
Do I need selenium-server for a local test?
No. The Java client is enough for the ordinary local WebDriver arrangement. Server is a separate artifact for remote server or Grid use.
Can I use Maven to run a Java main class?
Maven’s standard test lifecycle runs configured tests, not every main class. Run the sample from an IDE or configure an execution plugin; use a test framework for repeatable automated tests.


