Free tools Windows power users keep installed
One-click scans. No signup required.
To use Selenium with JavaScript, install the selenium-webdriver npm package, create a WebDriver session with Builder, await browser commands, and always close the session with driver.quit(). The current Selenium JavaScript API lists Node.js 22 or newer as its requirement; check the official API documentation for current compatibility details.
Install Selenium for Node.js
In a new or existing Node.js project, install Selenium’s JavaScript binding:
npm install selenium-webdriver
The package is named selenium-webdriver. At the time reflected in the current API documentation, supported Node.js lines are 22, 24, and 26; their listed support end dates are April 30, 2027, April 30, 2028, and April 30, 2029, respectively. These are version-sensitive details, so confirm them in the live JavaScript API documentation before choosing a runtime for a longer-lived project.
Run a first Selenium script
Save this CommonJS example as selenium.js in the project. It opens Chrome, visits Selenium’s sample form, enters text, submits it, checks the response, and quits even if an operation or assertion fails.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstall#1 Best Overall
const { By, Builder, Browser } = require('selenium-webdriver');
const assert = require('node:assert/strict');
(async function run() {
const driver = await new Builder().forBrowser(Browser.CHROME).build();
try {
await driver.get('https://www.selenium.dev/selenium/web/web-form.html');
const input = await driver.findElement(By.name('my-text'));
const submit = await driver.findElement(By.css('button'));
await input.sendKeys('Selenium');
await submit.click();
const message = await driver.findElement(By.id('message'));
assert.equal(await message.getText(), 'Received!');
} finally {
await driver.quit();
}
})();
Run it with:
node selenium.js
WebDriver calls are asynchronous in the JavaScript binding. Await navigation, element lookup, typing, clicking, and reading text; otherwise code may move on before the browser operation finishes. The finally block ensures that the browser session is closed after a failure as well as after a successful assertion.
Choose a browser and locate elements
Select the browser
The Builder configuration selects the browser. For Chrome, the example uses .forBrowser(Browser.CHROME). Firefox can be selected with .forBrowser(Browser.FIREFOX); browser-specific configuration belongs on the Builder setup. The target browser must be available in the environment where the session runs.
Rank #2
Use stable locators
Selenium’s By helpers locate elements by attributes or selectors. The sample uses By.name('my-text'), By.css('button'), and By.id('message'). Prefer stable page semantics or test-owned attributes where the application provides them. Broad selectors such as a generic button selector can become ambiguous when a page changes; narrow the selector to the intended control if that happens.
Wait for the page condition you need
Do not assume that an arbitrary sleep is the right synchronization strategy. Choose a wait based on the page’s behavior—for example, wait until a result element is present or visible when the application updates asynchronously. A fixed delay can be too short on a slow run and waste time on a fast one. Selenium’s JavaScript setup material shows timeout configuration and test-runner setup/teardown patterns in its organizing and executing Selenium code guide.
How Selenium Manager handles browser drivers
WebDriver is a language-neutral API and protocol for controlling browsers; a browser-specific driver mediates communication between Selenium and the browser. Selenium Manager is the Selenium project’s official driver manager and ships with Selenium releases. When a driver has not already been supplied, Selenium bindings use Selenium Manager as a fallback. It can identify the installed browser version, resolve and download a compatible driver, and cache it locally. Automated management of browser releases as well as drivers was added in Selenium 4.11.0. See the Selenium Manager documentation for details.
For an ordinary local setup, start with the default Builder and let Selenium Manager resolve the driver. You can still manage drivers yourself when an environment requires explicit control. For remote execution, configure the server URL instead of treating the remote browser as a local installation.
Rank #4
Run Selenium on a remote Grid or server
A local run starts a session against a browser provisioned on the machine running the Node.js script. A remote run sends commands to a Selenium Grid or standalone server, which owns the browser session and its browser/driver provisioning. The official JavaScript API documents both Builder server configuration and the SELENIUM_REMOTE_URL setting.
const { Builder, Browser } = require('selenium-webdriver');
const driver = await new Builder()
.forBrowser(Browser.CHROME)
.usingServer('http://localhost:4444')
.build();
Use the actual reachable URL of your Grid or server in place of the local example. The Builder route and server URL determine where the browser runs; they do not install or provision a remote browser for you. Consult the API reference for the current remote configuration options.
Best Value
Troubleshoot common setup failures
- Node version is unsupported: Check
node --versionand compare it with the Node.js requirement in the live Selenium JavaScript API documentation. Upgrade to a currently supported Node.js line if needed. - Session creation cannot find or start the browser: Confirm the selected browser is installed and available to the process. With the default Builder, Selenium Manager needs to resolve a compatible driver; check that the environment can reach its metadata and download endpoints.
- Driver and browser versions do not match: Let Selenium Manager handle the missing driver first. If you intentionally pin or provide a driver, verify that it is compatible with the browser version installed in that environment.
- The script exits before an action completes: Await each WebDriver operation, including element lookup and result reads. Keep session cleanup in
finallyor the test framework’s teardown hook. - An element lookup fails or returns the wrong element: Check that the page has reached the expected state, then verify the locator against the current DOM. Prefer a specific stable attribute or selector over a broad match.
- A remote session cannot connect: Verify that the Grid or standalone server is running and reachable from the Node.js process, and that the configured URL points to that server rather than to a local browser.
Or skip the browser setup
If your goal is a screenshot rather than browser interaction and assertions, ScreenshotNeo can return an image or PDF from one API request. Its API can accept consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents.
For example, the following cURL request saves a WebP screenshot; replace the URL with the page you need and provide your API key. See the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for 1,000 free screenshots a month, with no card required.
Quick Recap
Sources and further reading
- Selenium JavaScript API
- Selenium Manager
- Selenium getting started and browser-driver roles
- Organizing and executing Selenium code
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.
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 errors




