Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
selenium-webdriver
Advanced tools
The official WebDriver JavaScript bindings from the Selenium project
The selenium-webdriver npm package is a browser automation library that provides an API for interacting with web browsers. It allows for the automation of web applications for testing purposes, but it's also used for automating web-based administration tasks. It supports multiple browsers including Chrome, Firefox, Internet Explorer, and Safari.
Browser Navigation
This feature allows for navigating to a web page. The code sample demonstrates how to open Firefox and navigate to Google's homepage.
const {Builder} = require('selenium-webdriver');
let driver = new Builder().forBrowser('firefox').build();
driver.get('http://www.google.com');
Element Interaction
This feature enables interaction with elements on a web page, such as input fields and buttons. The code sample shows how to find a search input by its name attribute and type 'selenium' into it.
const {Builder, By} = require('selenium-webdriver');
let driver = new Builder().forBrowser('firefox').build();
driver.findElement(By.name('q')).sendKeys('selenium');
Wait for Elements
This feature allows scripts to wait for elements to become available or visible on the page before interacting with them. The code sample demonstrates waiting up to 10 seconds for a search input to be located.
const {Builder, By, until} = require('selenium-webdriver');
let driver = new Builder().forBrowser('firefox').build();
driver.wait(until.elementLocated(By.name('q')), 10000);
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. It is similar to selenium-webdriver but is specifically designed for Chrome and Chromium browsers. Puppeteer is often considered faster for browser automation tasks, especially with headless Chrome.
WebdriverIO is an automation library that wraps around the W3C WebDriver API. It provides a simpler API compared to selenium-webdriver and integrates well with modern testing frameworks. WebdriverIO supports both web and mobile browsers, making it a versatile choice for cross-platform testing.
Nightwatch.js is an automated testing framework for web applications and websites, written in Node.js. It uses the W3C WebDriver API for browser automation. It is designed to simplify the process of setting up continuous integration and writing automated tests. Nightwatch has a cleaner syntax compared to selenium-webdriver, which might be easier for beginners.
Install the latest published version using npm
:
npm install selenium-webdriver
In addition to the npm package, you will to download the WebDriver
implementations you wish to utilize. As of 2.34.0, selenium-webdriver
natively supports the ChromeDriver.
Simply download a copy and make sure it can be found on your PATH
. The other
drivers (e.g. Firefox, Internet Explorer, and Safari), still require the
standalone Selenium server.
To run the tests, you will need to download a copy of the
ChromeDriver and make
sure it can be found on your PATH
.
npm test selenium-webdriver
To run the tests against multiple browsers, download the
Selenium server and
specify its location through the SELENIUM_SERVER_JAR
environment variable.
You can use the SELENIUM_BROWSER
environment variable to define a
comma-separated list of browsers you wish to test against. For example:
export SELENIUM_SERVER_JAR=path/to/selenium-server-standalone-2.33.0.jar
SELENIUM_BROWSER=chrome,firefox npm test selenium-webdriver
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
driver.quit();
API documentation is included in the docs module. The API documentation for the current release are also available online from the Selenium project. A full user guide is available on the Selenium project wiki.
Please report any issues using the Selenium issue tracker.
Copyright 2009-2014 Software Freedom Conservancy
Licensed 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.
FAQs
The official WebDriver JavaScript bindings from the Selenium project
We found that selenium-webdriver demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.