npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

selenium-adapter

v0.2.7

Published

A promise adapter for Selenium WebDriver for use with ES2017 async/await

Readme

selenium-adapter

Build Status

A promise adapter for Selenium WebDriver for use with ES2017 async/await.

Installing

selenium-adapter is available as an npm package.

Dependencies

ChromeDriver depends on the system libraries libxi6 and libgconf-2-4, which need to be installed before installing selenium-adapter.

Note that selenium-adapter is only tested against recent versions of Chrome and Firefox.

Usage

import {
  makeHeadlessChromeAdapter,
  close,
  navigate,
  findElement,
  click,
  fillIn,
  getText
} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await navigate(chrome, 'https://www.google.com')

  const searchBox = await findElement(chrome, 'input[name="q"]')
  await fillIn(searchBox, 'Hello World!')

  const searchButton = await findElement(chrome, 'input[value="Search"]')
  await click(searchButton)

  const body = await findElement(chrome, 'body')

  console.log(await getText(body))
}
run();

Choosing a Browser

function makeChromeAdapter(): WebDriver

import {makeChromeAdapter} from 'selenium-adapter'

async function run() {
  const chrome = makeChromeAdapter()
}
run();

Creates a Selenium WebDriver instance that controls a Chrome/Chromium browser via ChromeDriver.

function makeHeadlessChromeAdapter(): WebDriver

import {makeHeadlessChromeAdapter} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
}
run();

Creates a Selenium WebDriver instance that controls a Chrome/Chromium browser in headless mode via ChromeDriver.

function makeFirefoxAdapter(): WebDriver

import {makeFirefoxAdapter} from 'selenium-adapter'

async function run() {
  const firefox = makeFirefoxAdapter()
}
run();

Creates a Selenium WebDriver instance that controls a Firefox browser via GeckoDriver.

function makePhantomAdapter(): WebDriver

import {makePhantomAdapter} from 'selenium-adapter'

async function run() {
  const phantom = makePhantomAdapter()
}
run();

Creates a Selenium WebDriver instance that controls a PhantomJS browser.

Interacting With The Browser

function close(adapter: WebDriver): Promise<void>

import {makeHeadlessChromeAdapter, close} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await close(chrome)
}
run();

Closes the browser and Selenium WebDriver client.

function navigate(adapter: WebDriver, url: string): Promise<void>

import {makeHeadlessChromeAdapter, navigate} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await navigate(chrome, 'https://google.com')
}
run();

Navigate to a given URL.

In Chrome, if navigation fails due to a connection error or an HTTP status code in the 400s or 500s, an error will be raised.

function evaluate<T> (adapter: WebDriver, fn: () => T): Promise<T>

import {makeHeadlessChromeAdapter, navigate, evaluate} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await navigate(chrome, 'https://google.com')
  console.log(await evaluate(chrome, () => document.title))
}
run();

Evaluate a JavaScript function within the context of the currently open page. The function's return value is serialized and returned. Note that the function will only have access to local variables defined inside of the function.

function findElement (adapterOrElement: WebDriver | ?WebDriverElement, selector: string, text: ?string): Promise<?WebDriverElement>

import {
  makeHeadlessChromeAdapter,
  navigate,
  findElement
} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await navigate(chrome, 'https://www.npmjs.com')
  const header = await findElement(chrome, 'header')
  const searchBox = await findElement(header, '[name="q"]')
  const searchSubmit = await findElement(header, 'button', 'Search')
}
run();

Finds the first element matching a CSS selector and optionally containing a string. If no matching element is found, null is returned. If an adapter is given as first argument, the search is scoped to the entire page. If an element is given, the search is scoped to only descendants of that element.

For the use case of finding an element that will exist after a delay (e.g. upon completion of an HTTP request), see waitFor

Interacting With Elements

function getAttribute (element: ?WebDriverElement): Promise<?string>

import {
  makeHeadlessChromeAdapter,
  navigate,
  findElement,
  getAttribute
} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await navigate(chrome, 'https://www.npmjs.com')
  const searchBox = await findElement(chrome, 'input[name="q"]')
  console.log(await getAttribute(searchBox, 'value'))
  console.log(await getAttribute(searchBox, 'placeholder'))
}
run();

Reads an attribute, or if not present, a property by name for an element.

function getText (element: ?WebDriverElement): Promise<?string>

import {
  makeHeadlessChromeAdapter,
  navigate,
  findElement,
  getText
} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await navigate(chrome, 'https://www.npmjs.com')
  const title = await findElement(chrome, 'h1')
  console.log(await getText(title))
}
run();

Reads the text contained within an element.

function click (element: ?WebDriverElement): Promise<void>

import {
  makeHeadlessChromeAdapter,
  navigate,
  findElement,
  click
} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await navigate(chrome, 'https://www.npmjs.com')
  const signUp = await findElement(chrome, 'a', 'Sign up for npm')
  await click(signUp)
}
run();

Clicks on a given element

function fillIn (element: ?WebDriverElement, value: string): Promise<void>

import {
  makeHeadlessChromeAdapter,
  navigate,
  findElement,
  fillIn
} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await navigate(chrome, 'https://www.npmjs.com')
  const searchBox = await findElement(chrome, '[name="q"]')
  await fillIn(searchBox, 'A Query')
  await fillIn(searchBox, 'A Different Query')
}
run();

Given an input element, clears its value and types in a new value.

Utilities

function waitFor<T> (time: number, getResult: () => Promise<T>): Promise<?T>

import {
  makeHeadlessChromeAdapter,
  navigate,
  findElement,
  waitFor
} from 'selenium-adapter'

async function run() {
  const chrome = makeHeadlessChromeAdapter()
  await navigate(chrome, 'http://localhost:8080')
  const delayedButton = waitFor(2000, () => findElement(chrome, 'button'))
}
run();

Run the given function over and over until it returns a truthy value. If a truthy value is not returned within the given number of milliseconds, null is returned.