Recommended Free Tools
Use Selenium WebDriver when you want Java bindings built around the WebDriver standard and its browser-driver/Grid ecosystem. Use Playwright for Java when Chromium, WebKit and Firefox support plus Playwright-managed browser binaries fit your project. Both approaches create a browser session, open a URL, locate elements, perform actions and close the session. This guide gives working Java patterns, setup decisions, reliability guidance and a route that avoids maintaining browser automation infrastructure.
What you need before writing Java automation
- A supported JDK installed and available on your
PATH. - Maven or Gradle to resolve Java libraries.
- A browser for Selenium, together with the browser-specific driver implementation required by your chosen browser. Selenium’s setup guidance covers the language library, browser and driver: Selenium WebDriver getting started.
- For Playwright, the Java library and the browser binaries installed by Playwright’s CLI. The binaries are matched to the Playwright release, so repeat the browser-install step after upgrading Playwright; see Playwright Java installation and Playwright browser management.
Documentation labels, supported Java versions, browser versions and commands change. Check the linked official pages when creating a new project rather than copying an old version number.
Automate a browser with Selenium WebDriver
Add the Selenium Java binding
Selenium distributes its Java binding as org.seleniumhq.selenium:selenium-java. Add that artifact through Maven or Gradle and select the current version shown on Selenium’s Java library installation page. Keeping the version in your build configuration, instead of hard-coding it in application code, makes upgrades auditable.
After the dependency is resolved, make sure the browser and its driver implementation are available to the environment that runs the test or job. A driver built for a different browser or an incompatible browser version can prevent a session from starting.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsYour first complete Selenium program
The following class demonstrates the complete lifecycle documented in Selenium’s first-script guide: create a driver, navigate, locate an element, interact with it, read a result and always quit.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class BrowserSmoke {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
try {
driver.get("https://example.com");
WebElement heading = driver.findElement(By.cssSelector("h1"));
System.out.println("Heading: " + heading.getText());
WebElement link = driver.findElement(By.cssSelector("a"));
link.click();
System.out.println("After click: " + driver.getTitle());
} finally {
driver.quit();
}
}
}
driver.get waits for navigation to begin, but it does not guarantee that every application element is ready. findElement locates an element using a strategy such as an ID, CSS selector, name, link text or XPath. click, sendKeys and related methods perform user-like actions. quit ends the entire session; put it in finally so a failed assertion or lookup does not leave browser processes running.
Wait for application state instead of sleeping
Dynamic pages often render controls after an API response. A fixed Thread.sleep is either too short or needlessly slow. Use an explicit wait for the condition that makes the next action valid:
Rank #2
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
WebElement submit = wait.until(
ExpectedConditions.elementToBeClickable(By.cssSelector("button[type='submit']")));
submit.click();
wait.until(ExpectedConditions.urlContains("success"));
Choose a condition that reflects the user-visible state: presence when the element merely needs to exist, visibility when it must be displayed, clickability before a click, or a URL/title condition after navigation. Keep selectors tied to stable IDs, roles or data attributes when your application provides them; long, layout-dependent XPath expressions are harder to maintain.
Keep sessions isolated
Create one driver per independent test or workflow and quit it in that workflow’s cleanup. Do not share a mutable driver between parallel tests unless your runner explicitly provides isolation. For remote execution, Selenium documents Grid as the route for distributing browser sessions and WebDriver as a W3C Recommendation: WebDriver documentation.
Use Playwright from Java
Playwright’s Java package is also delivered through Maven. Its setup adds a separate step: install the browser binaries through the Playwright CLI, using the command documented for the exact Playwright release. A commonly used Maven invocation is:
mvn exec:java -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="install"
Verify the command and required Maven plugin configuration against the current browser installation documentation. When the Playwright dependency is upgraded, run the matching browser installation again; the binaries are version-specific.
A minimal Java session looks like this:
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
public class PlaywrightSmoke {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(
new BrowserType.LaunchOptions().setHeadless(true));
Page page = browser.newPage();
page.navigate("https://example.com");
System.out.println(page.title());
System.out.println(page.locator("h1").innerText());
browser.close();
}
}
}
Playwright’s Java documentation covers Chromium, WebKit and Firefox. Select the browser explicitly when the project requires a particular engine, and install the corresponding binaries. Its locator model can wait for an element to become actionable, which keeps the code close to the user action; still, define assertions that describe the state your test must verify.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Selenium or Playwright: choose by workflow
| Decision point | Selenium WebDriver | Playwright for Java |
|---|---|---|
| Browser strategy | Uses browser-specific WebDriver implementations. | Uses Playwright-managed binaries tied to the selected Playwright release. |
| Java setup | Add org.seleniumhq.selenium:selenium-java through Maven or Gradle, then provide the browser and driver. |
Add the Playwright Maven module and run the release-matched browser installation CLI. |
| Browser engines documented here | Choose the browsers and drivers supported by your Selenium environment. | Chromium, WebKit and Firefox are documented for Java. |
| Standards and ecosystem | WebDriver is a W3C Recommendation; Selenium documents Grid for distributed execution. | Uses Playwright’s API and release-controlled browser packages. |
| Best fit | Teams standardizing on WebDriver, existing Selenium suites or Grid workflows. | Projects that want Playwright’s browser-version workflow and its documented engine coverage. |
| Performance expectation | The available documentation does not establish a controlled speed or reliability winner. Measure your own pages, CI runners and remote infrastructure. | |
For local development, keep the browser setup reproducible in the build instructions. For CI, cache only binaries that match the library version, expose required credentials through the runner’s secret store, and publish screenshots, logs and test reports as artifacts. For a distributed Selenium estate, plan the Grid endpoint, session capacity and cleanup policy separately from test code.
Rank #4
Troubleshoot common failures
| Symptom | Likely cause | Fix |
|---|---|---|
SessionNotCreatedException when constructing ChromeDriver |
The browser, driver implementation and Selenium binding are not compatible, or the driver cannot be found. | Check the browser version, driver installation and current Selenium setup instructions. Run the same checks on the CI machine, not only your laptop. |
NoSuchElementException |
The selector is wrong, the page changed, or the element has not rendered yet. | Inspect the live DOM, prefer a stable selector and wait for the relevant condition before locating or clicking. |
ElementClickInterceptedException |
An overlay, animation or other element is covering the target. | Wait for the overlay to disappear or for the target to become clickable; do not hide the failure with an arbitrary long sleep. |
| Timeout after navigation | The page is slow, blocked by the environment or waiting on a resource that never completes. | Capture the URL and browser logs, verify network access from the runner, and set a timeout appropriate to the application rather than retrying indefinitely. |
| Playwright reports missing executable | The browser binaries were not installed, or they do not match the Playwright library version. | Run the CLI install command from the current Playwright Java browser guide for that release, then repeat it after upgrades. |
| Works locally but fails in CI | Different browser versions, missing drivers/binaries, permissions, environment variables or network access. | Record library and browser versions in the job log, install dependencies in the image, and make the same navigation and credentials available to the runner. |
Or skip the browser setup: ScreenshotNeo
If your goal is a rendered screenshot or PDF rather than clicking through a workflow, ScreenshotNeo provides a single HTTP request. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers.
See the ScreenshotNeo API documentation for current parameters. These examples use the supplied endpoint and URL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Java callers can use the same endpoint with java.net.http.HttpClient or an HTTP library already used by the application; the response body is the PNG, JPEG, WebP or PDF selected by the request options.
Options for automated captures
- Full-page screenshots with lazy images loaded, or one element selected by CSS.
- Dark mode, 12 device presets, arbitrary viewport sizes and retina scale.
- PDF paper size, margins, landscape mode and page ranges.
- HTML/CSS to image, custom CSS and JavaScript, a click before capture, hidden selectors and waits for a selector, delay or network idle.
- Blocking for ads, trackers, requests or resource types; custom headers, cookies, user agent and Authorization; timezone and geolocation.
- Transparent backgrounds, image resizing, a chosen cache TTL, signed links for public
<img>tags, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification. - Parameter names used by other screenshot APIs are accepted, which can simplify migration.
- An MCP server exposes
take_screenshot,get_page_infoandcapture_pdfto Claude, Cursor and other MCP clients.
| Plan | Included screenshots | Price |
|---|---|---|
| Free | 1,000 per month | $0, no card |
| Starter | 3,000 | $5 |
| Growth | 15,000 | $15 |
| Pro | 60,000 | $39 |
| Scale | 250,000 | $99 |
| Business | 1,000,000 | $249 |
Yearly billing gives two months free, and every feature is on every plan. Start with 1,000 free screenshots a month without a card.
Best Value
A practical selection checklist
- Choose Selenium if WebDriver compatibility, an existing Selenium codebase or Selenium Grid is a requirement.
- Choose Playwright if its Chromium, WebKit and Firefox coverage and version-managed browser installation match your release process.
- Use explicit waits and stable selectors in either framework; record the browser and library versions in CI.
- Use ScreenshotNeo when the deliverable is a clean screenshot or PDF and maintaining a browser session is unnecessary.
Frequently Asked Questions
Can Java automate more than one browser?
Yes. Selenium selects a browser through its corresponding WebDriver implementation. Playwright for Java documents Chromium, WebKit and Firefox; install the binaries that match the Playwright release you use.
Where should credentials for automated pages be stored?
Keep them in your CI or runtime secret store and inject them at execution time. Do not commit passwords, cookies or Authorization values to Java source or build files.
How do I decide whether to run locally or remotely?
Run locally while developing selectors and waits. Move to CI or Selenium Grid when you need repeatable runner environments, parallel sessions or centralized browser capacity.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

