Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Selenium’s JavaScript binding, mark your test or helper async and await WebDriver calls and waits that return promises. Use executeAsyncScript only when you need JavaScript running inside the browser page to perform asynchronous work and return a result through Selenium’s callback. Those are different kinds of waiting: one is in your Node.js test code; the other is in the page context.

Await WebDriver commands in JavaScript test code

WebDriver operations in Selenium’s JavaScript binding return promises. Put the sequence in an async function and await each operation whose result the next step depends on. This representative pattern builds a Chrome session, opens a page, waits for a button to exist, clicks it, waits for the title to change, and quits the browser even if a step fails:

const { Builder, By, until } = require('selenium-webdriver');

async function example() {
  const driver = await new Builder().forBrowser('chrome').build();
  try {
    await driver.get('https://example.test');
    const button = await driver.wait(
      until.elementLocated(By.id('continue')),
      10_000
    );
    await button.click();
    await driver.wait(until.titleIs('Next step'), 10_000);
  } finally {
    await driver.quit();
  }
}

example().catch(error => {
  console.error(error);
  process.exitCode = 1;
});

The example assumes the selenium-webdriver package is installed, Chrome is available to the WebDriver setup, and the page has the specified element and title behavior. The waits are capped at 10 seconds; if a condition is not met, the wait rejects and the error reaches the caller. The finally block ensures the session is asked to close on either success or failure.

await driver.get(...) waits for the WebDriver command’s promise to resolve. It does not make JavaScript in the page asynchronous or, by itself, establish that a particular application component is ready.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Wait for application state instead of sleeping

When the next test step depends on a UI state, use driver.wait(condition, timeout) with a condition that expresses that state. Selenium’s JavaScript wait API repeatedly evaluates conditions and also accepts promise-like conditions. For example, until.elementLocated(By.id('continue')) waits for an element to be located; it does not necessarily mean the element is visible, enabled, or safe to click. Choose a condition that matches the next action, or wait for the relevant state explicitly.

A fixed delay such as await driver.sleep(2000) consumes that time even when the page is ready sooner, and still does not prove readiness if the page takes longer. A condition-based wait ties the test to the event it needs and fails at a defined timeout if it never occurs.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Run asynchronous JavaScript inside the page

Use driver.executeAsyncScript when the test needs to initiate or observe asynchronous work in the selected browser frame and return a value to Node.js. Selenium appends an injected completion callback as the final argument to the page function. The page script must call it to signal completion:

const value = await driver.executeAsyncScript(function () {
  const done = arguments[arguments.length - 1];
  fetch('/api/status')
    .then(response => response.json())
    .then(data => done(data.status))
    .catch(error => done({ error: String(error) }));
});

This is a callback contract, not a promise-return contract: do not assume Selenium will wait simply because the page function returns a Promise. If the callback is never invoked, the command remains pending until the script timeout. The supplied function is serialized for execution in the page, so it cannot rely on lexical variables from the Node.js test process. Pass data into the page through supported script arguments, or make the page function self-contained.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

For many synchronization problems, a WebDriver wait for a visible or otherwise meaningful UI condition is clearer than starting a page-side fetch. Use executeAsyncScript when the browser-context operation itself and its returned value are what the test needs.

Choose the right kind of wait

Need Use How it completes
Sequence commands in the JavaScript WebDriver binding async function with await on driver calls The WebDriver promise resolves or rejects.
Wait until a UI condition becomes true driver.wait(condition, timeout) The condition resolves truthy, or the wait times out.
Run asynchronous JavaScript in the selected page frame and return a value driver.executeAsyncScript(...) The page script calls Selenium’s injected callback.

Set a bounded script timeout

The Selenium JavaScript WebDriver implementation documentation accessed in 2026 documents a default script timeout of 30000 milliseconds. Defaults may depend on the installed binding and version, so check the API for the version in your project rather than treating that value as universal. Set a session script timeout appropriate to the page-side operation, and keep it bounded so a missing callback does not leave the test waiting indefinitely.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Timeout configuration is binding-specific. Python uses driver.set_script_timeout(seconds) with execute_async_script; Java uses the WebDriver timeout API with JavascriptExecutor.executeAsyncScript. Do not copy those method names or their syntax into JavaScript tests.

Troubleshoot common async and await failures

  • A test moves on before a WebDriver operation finishes: Make the helper or test function async and await the relevant WebDriver promise. Returning a promise from a helper is also valid if its caller awaits it.
  • executeAsyncScript hangs until timeout: Check every success and error path in the page function and ensure each calls the injected callback exactly once. A rejected fetch or a parsing error that is not handled can otherwise leave completion unreported.
  • The page function cannot read a Node.js variable: The function runs in the page after serialization; Node lexical scope is not available there. Make it self-contained or pass needed values using the script-execution arguments supported by WebDriver.
  • The test clicks too early after locating an element: Location alone may not establish visibility or enabled state. Wait for the specific state required by the action.
  • A fixed sleep is flaky or slow: Replace it with a condition-based wait for the application state the test actually needs, with an explicit timeout.
  • A timeout example from another language does not work: Confirm the binding. JavaScript, Python, and Java expose different method names and configuration patterns.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup:

If your goal is a rendered page capture rather than a Selenium interaction test, ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request returns a PNG, JPEG, WebP, or PDF. For example, this cURL call saves a WebP capture of Stripe; create an API key first. See the ScreenshotNeo API documentation for request options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Cookie and consent banners are accepted before capture, and 60+ known consent platforms, newsletter popups, and chat widgets can be removed; each step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and whether the request was billed.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents including Claude, Cursor, and other MCP clients.
  • The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.