Selenium is a browser automation library. Most often used for testing web-applications, Selenium may be used for any task that requires automating interaction with the browser.
Selenium may be installed via npm with
npm install selenium-webdriverYou will need to download additional components to work with each of the major browsers. The drivers for Chrome, Firefox, and Microsoft's IE and Edge web browsers are all standalone executables that should be placed on your systemPATH. Apple's safaridriver (v10 and above) can be found at the following path – /usr/bin/safaridriver. To enable automation on safari, you need to run commandsafaridriver --enable.
| Browser | Component |
|---|---|
| Chrome | chromedriver(.exe) |
| Internet Explorer | IEDriverServer.exe |
| Edge | MicrosoftWebDriver.msi |
| Firefox | geckodriver(.exe) |
| Opera | operadriver(.exe) |
| Safari | safaridriver |
The sample below and others are included in theexample directory. You may also find the tests for selenium-webdriver informative.
const { Builder, Browser, By, Key, until } = require('selenium-webdriver');(async function example() { let driver = await new Builder().forBrowser(Browser.FIREFOX).build() try { await driver.get('https://www.google.com/ncr') await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN) await driver.wait(until.titleIs('webdriver - Google Search'), 1000) } finally { await driver.quit() }})()TheBuilder class is your one-stop shop for configuring new WebDriver instances. Rather than clutter your code with branches for the various browsers, the builder lets you set all options in one flow. When you callBuilder#build(), all options irrelevant to the selected browser are dropped:
const webdriver = require('selenium-webdriver')const chrome = require('selenium-webdriver/chrome')const firefox = require('selenium-webdriver/firefox')let driver = new webdriver.Builder() .forBrowser(webdriver.Browser.FIREFOX) .setChromeOptions(/* ... */) .setFirefoxOptions(/* ... */) .build()Why would you want to configure options irrelevant to the target browser? TheBuilder's API defines yourdefault configuration. You can change the target browser at runtime through theSELENIUM_BROWSER environment variable. For example, theexample/google_search.js script is configured to run against Firefox. You can run the example against other browsers just by changing the runtime environment
# cd node_modules/selenium-webdrivernode example/google_searchSELENIUM_BROWSER=chrome node example/google_searchSELENIUM_BROWSER=safari node example/google_searchThe standalone Selenium Server acts as a proxy between your script and the browser-specific drivers. The server may be used when running locally, but it's not recommend as it introduces an extra hop for each request and will slow things down. The server is required, however, to use a browser on a remote host (most browser drivers, like the IEDriverServer, do not accept remote connections).
To use the Selenium Server, you will need to install theJDK and download the latest server fromSelenium. Once downloaded, run the server with
java -jar selenium-server-4.27.0.jar standaloneYou may configure your tests to run against a remote server through the Builder API:
let driver = new webdriver.Builder() .forBrowser(webdriver.Browser.FIREFOX) .usingServer('http://localhost:4444/wd/hub') .build()Or change the Builder's configuration at runtime with theSELENIUM_REMOTE_URL environment variable:
SELENIUM_REMOTE_URL="http://localhost:4444/wd/hub" node script.jsYou can experiment with these options using theexample/google_search.js script provided withselenium-webdriver.
API documentation is available online from theSelenium project. Additional resources include
Contributions are accepted either throughGitHub pull requests or patches via theSelenium issue tracker.
Each version of selenium-webdriver will support the latestsemver-minor version of theLTS and stable Node releases. Allsemver-major &semver-minor versions between the LTS and stable release will have "best effort" support. Following a Selenium release, anysemver-minor Node releases will also have "best effort" support. Releases older than the latest LTS,semver-major releases, and all unstable release branches (e.g. "v.Next") are considered strictly unsupported.
For example, suppose the current LTS and stable releases are v22.13.0 and v23.6.0, respectively. Then a Selenium release would have the following support levels:
| Version | Support |
|---|---|
| <= 16.20.2 | unsupported |
| 16.20.2 | supported |
| 18.8.0 | supported |
| >= 22.13.0 | best effort |
| v.Next | unsupported |
supported: A selenium-webdriver release will be API compatible with the platform API, without the use of runtime flags.
best effort: Bugs will be investigated as time permits. API compatibility is only guaranteed where required by asupported release. This effectively means the adoption of new JS features, such as ES2015 modules, will depend on what is supported in Node's LTS.
unsupported: Bug submissions will be closed as will-not-fix and API compatibility is not guaranteed.
If Node releases a newLTS each October and a new major version every 6 months, the support window for selenium-webdriver will be roughly:
| Release | Status | END-OF-LIFE |
|---|---|---|
| v18.x | Maintenance LTS | 2025-04-30 |
| v19.x | End-of-Life | 2023-06-01 |
| v20.x | Maintenance LTS | 2026-04-30 |
| v21.x | End-of-Life | 2024-06-01 |
| V22.x | Active LTS | 2027-04-30 |
| V23.x | Current | 2025-06-01 |
Please report any issues using theSelenium issue tracker. When using the issue tracker
Licensed to the Software Freedom Conservancy (SFC) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The SFC licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.