The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →To run Selenium tests with Node.js, install Node.js 22 or newer, add the selenium-webdriver package, and write an asynchronous test that starts a browser, interacts with a page, checks the result, and always closes the browser session. Selenium Manager ordinarily handles browser-driver setup, so you usually do not need to download ChromeDriver first. The examples below show a direct script and a Mocha test you can run locally.
Before you start
- Node.js: The current Selenium JavaScript API documentation requires Node.js 22 or newer. Its listed support end dates are April 30, 2027 for Node 22, April 30, 2028 for Node 24, and April 30, 2029 for Node 26. Check the Selenium JavaScript API documentation when choosing or upgrading a Node release.
- A browser: Install the browser you intend to automate, such as Chrome, in the environment where the script will run.
- A project directory: The commands below use npm and can be run in a new or existing Node.js project.
In a terminal, initialize the project if it does not already have a package.json, then install Selenium’s JavaScript binding:
mkdir selenium-node-tests
cd selenium-node-tests
npm init -y
npm install selenium-webdriver
The package install command is documented in the Selenium WebDriver JavaScript API.
Run a basic Selenium script
This CommonJS example opens Selenium’s website in Chrome, prints the page title, and closes the session even if navigation or title retrieval fails:
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
const { Builder, Browser } = require('selenium-webdriver');
(async function example() {
let driver;
try {
driver = await new Builder().forBrowser(Browser.CHROME).build();
await driver.get('https://www.selenium.dev');
console.log(await driver.getTitle());
} finally {
if (driver) await driver.quit();
}
})();
Save it as first-test.js and run:
node first-test.js
The sequence is the foundation of a browser test: construct a Builder, select a browser, wait for asynchronous WebDriver operations, inspect or assert page state, and call quit() to end the session. The guard on driver also avoids trying to close a session if creation itself failed. Selenium’s first-script guide demonstrates the basic browser workflow.
Organize repeatable tests with Mocha
A direct script is handy for a first check. A test runner becomes more useful when you need named cases, setup and teardown hooks, and a failing process status when an assertion fails. Selenium’s JavaScript guide demonstrates Mocha. Install it as a development dependency:
Rank #2
npm install --save-dev mocha
Create runningTests.spec.js:
const { By, Builder, Browser } = require('selenium-webdriver');
const assert = require('node:assert/strict');
describe('Web form', function () {
let driver;
before(async function () {
driver = await new Builder().forBrowser(Browser.CHROME).build();
});
it('submits text and shows the response', async function () {
await driver.get('https://www.selenium.dev/selenium/web/web-form.html');
await driver.findElement(By.name('my-text')).sendKeys('Selenium');
await driver.findElement(By.css('button')).click();
assert.equal(await driver.findElement(By.id('message')).getText(), 'Received!');
});
after(async function () {
if (driver) await driver.quit();
});
});
Run the test from the project directory:
npx mocha runningTests.spec.js
Mocha runs the before hook to create the browser session, executes the asynchronous test case, and then runs after to close the session. The test demonstrates locating by a name and CSS selector, entering text, clicking a button, and asserting the resulting text. See Selenium’s guide to organizing and executing Selenium code for its Mocha example and run command.
Do you need to install ChromeDriver?
Usually, no. WebDriver is the browser-control interface, while a browser-specific driver mediates between Selenium and the browser. Selenium Manager has been included with Selenium releases since 4.6, and Selenium bindings call it by default to manage routine driver setup. For the ordinary local setup above, start by installing Selenium and the browser rather than manually downloading a driver. The Selenium Project explains the roles in its Getting started guide and describes automatic driver management in its Selenium Manager documentation.
Rank #3
Manual configuration remains relevant in nonstandard environments—for example, if your organization requires a pinned or custom driver, or if you need special Chrome service or browser options. The Chrome module reference documents custom options and services; treat its download-and-PATH instructions as an advanced configuration path, not a prerequisite for every new project.
Run against a remote Selenium server
To use Selenium Grid or another reachable WebDriver server instead of starting a local browser session, configure the builder with the server URL. The Selenium JavaScript API documents this pattern:
Rank #4
const { Builder, Browser } = require('selenium-webdriver');
(async function example() {
let driver;
try {
driver = await new Builder()
.forBrowser(Browser.CHROME)
.usingServer('http://localhost:4444')
.build();
await driver.get('https://www.selenium.dev');
console.log(await driver.getTitle());
} finally {
if (driver) await driver.quit();
}
})();
The URL must point to a running, reachable server that offers the requested browser capability. You can also set SELENIUM_REMOTE_URL and launch a script with that environment variable; consult the API documentation for the supported configuration. A remote setup shifts browser execution and version management to the server environment, and network reachability becomes part of test setup. Confirm available browsers and capabilities with the Grid or server operator rather than assuming a particular configuration or parallelism level.
Common startup and test failures
| Symptom | Likely cause | What to check |
|---|---|---|
| Node rejects the Selenium package or the script fails before launching | The installed Node.js version may be below the binding’s documented minimum. | Check node --version and use Node.js 22 or newer, then verify the current compatibility information in the JavaScript API docs. |
| The browser session cannot start | The selected browser may be absent or unavailable to the process; Selenium Manager may also be unable to complete routine driver management in a restricted network environment. | Confirm the browser is installed in the environment running the test. Check proxy or network restrictions that could prevent Selenium Manager from working; do not assume it installs the browser itself. |
| A local test meant for Grid cannot connect | The remote URL is wrong, the server is stopped, or the server is unreachable from the test process. | Verify the configured URL, server status, network route, and browser capabilities exposed by the server. |
| The test cannot find an element or its assertion fails | The page may not have reached the expected state, the locator may not match the current page, or the expected text may differ. | Check the target URL and locator against the page, then verify the result the test is asserting. Keep interactions and reads awaited so they complete in order. |
| A browser remains open after a test run | Teardown was skipped or session cleanup was not guarded and reached on failure paths. | Close sessions in a Mocha after hook or a script’s finally block, checking that a driver was created before calling quit(). |
Choosing local or remote execution
| Approach | Who manages the browser environment | Useful when | Trade-off to plan for |
|---|---|---|---|
| Local WebDriver session | The developer or local test machine supplies the browser and runs it alongside the test. | Learning Selenium, debugging, or running a modest test locally. | Results depend on the local machine’s browser and environment. |
| Remote WebDriver session | The Grid or remote-server operator supplies the server and its configured browser capabilities. | Tests need to run against a shared or separately managed browser environment. | The test depends on server availability, network access, and the capabilities the server actually exposes. |
Selenium’s documentation describes both local session creation and remote Builder configuration, but does not establish a general speed advantage for either approach. Choose based on browser/OS coverage, environment ownership, network access, and who maintains browser versions.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
Or skip the browser setup
Selenium is for interactive browser automation and assertions. If the immediate task is simply to obtain a page screenshot or PDF, ScreenshotNeo offers a one-request website screenshot API, including a JavaScript example:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Replace the target URL and provide your API key. See the ScreenshotNeo API documentation for request options and response handling. ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be disabled. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per 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.
Frequently Asked Questions
Can I use Node’s built-in assert module with Selenium?
Yes. The Mocha example uses node:assert/strict for its result check.
Can Selenium automate browsers other than Chrome?
The JavaScript binding supports browser selection through Builder; the browser you request must be available locally or offered by the remote server.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →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.




