New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wait-for-the-element

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wait-for-the-element

A utility library that enables you to efficiently wait for an element to appear or disappear.

  • 4.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

wait-for-the-element

Available from NPM Built using GitHub Action

A utility library that enables you to efficiently wait for an element to appear or disappear.

Usage

This module can be treated as an ES module:

import { waitForTheElement, waitForTheElementToDisappear } from 'wait-for-the-element';

This module can also be treated as a CommonJS module:

const { waitForTheElement, waitForTheElementToDisappear } = require('wait-for-the-element');

Waiting for an element

You can wait for an element to match a provided selector and retrieve it:

const element = await waitForTheElement('.target', {
  timeout : 5000
});

if (element === null)
{
  // After 5 seconds, a matching element still doesn't exist.
}

Important Note: If the selector matches multiple elements, only the first match will be returned.

Waiting for an element to disappear

You can wait for all elements to stop matching a provided selector:

const hidden = await waitForTheElementToDisappear('.target', {
  timeout : 5000
});

if (!hidden)
{
  // After 5 seconds, a matching element still exists.
}

Selectors

All functions accept CSS selectors supported by document.querySelector().

Options

All functions accept an optional settings object that control how elements are searched for:

OptionsRequiredDefaultDescription
timeoutNo2500The maximum amount of time (in milliseconds) to wait.
scopeNodocumentThe root element to start searching from.

Getting started

This module is available through the Node Package Manager (NPM):

npm install wait-for-the-element

Development

Building

You can build UMD and ESM versions of this module that are both ES5 compatible and minified:

npm run build

Testing

This module also has a robust test suite:

npm test

This includes a code quality check using ESLint. Please refer to the .eslintrc files to familiar yourself with the rules.

License

This project is released under the MIT license.

Keywords

FAQs

Package last updated on 26 May 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc