What is @types/selenium-webdriver?
The @types/selenium-webdriver package provides TypeScript type definitions for the selenium-webdriver package, which is a browser automation framework. These type definitions allow developers to use Selenium with TypeScript by providing the necessary type annotations for better development experience, such as code completion and type checking.
What are @types/selenium-webdriver's main functionalities?
Browser Control
This feature allows you to control a browser programmatically, including opening pages, filling out forms, and simulating user actions.
import { Builder, By, Key, until } from 'selenium-webdriver';
(async function example() {
let driver = await new Builder().forBrowser('firefox').build();
try {
await driver.get('http://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();
}
})();
Element Interaction
This feature allows interaction with HTML elements on a web page, such as clicking buttons, entering text, and reading element attributes.
import { Builder, By } from 'selenium-webdriver';
(async function example() {
let driver = await new Builder().forBrowser('firefox').build();
try {
await driver.get('http://www.example.com');
let element = await driver.findElement(By.id('some-id'));
await element.click();
} finally {
await driver.quit();
}
})();
Wait Conditions
This feature provides the ability to wait for certain conditions to be met before proceeding with further actions, such as waiting for an element to be present or visible.
import { Builder, By, until } from 'selenium-webdriver';
(async function example() {
let driver = await new Builder().forBrowser('firefox').build();
try {
await driver.get('http://www.example.com');
await driver.wait(until.elementLocated(By.id('some-id')), 10000);
} finally {
await driver.quit();
}
})();
Other packages similar to @types/selenium-webdriver
webdriverio
WebdriverIO is a custom implementation for selenium's W3C webdriver API. It is written in JavaScript and packaged into 'npm'. It includes its own set of commands and is designed to be more user-friendly and feature-rich than the standard selenium-webdriver package.
protractor
Protractor is an end-to-end test framework for Angular and AngularJS applications. It runs tests against your application running in a real browser, interacting with it as a user would. Protractor is built on top of WebDriverJS and includes additional Angular-specific locator strategies and functions.
nightwatch
Nightwatch.js is an automated testing framework for web applications and websites, written in Node.js and using the W3C WebDriver API (formerly Selenium WebDriver). It is a complete browser (end-to-end) testing solution which aims to simplify the process of setting up Continuous Integration and writing automated tests.
puppeteer
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default but can be configured to run full (non-headless) Chrome or Chromium. It is not a direct implementation of the W3C WebDriver API and is typically used for browser automation, scraping, and testing.
Installation
npm install --save @types/selenium-webdriver
Summary
This package contains type definitions for Selenium WebDriverJS (https://github.com/SeleniumHQ/selenium).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/selenium-webdriver.
Additional Details
- Last updated: Tue, 18 Oct 2022 18:02:58 GMT
- Dependencies: @types/ws
- Global values: none
Credits
These definitions were written by Bill Armstrong, Yuki Kokubun, Craig Nishina, Simon Gellis, Ben Dixon, Ziyu, Johann Wolf, Aleksey Chemakin, David Burns, Pirasis Leelatanon, and Harmandeep Singh.