Skip to content

[🐛 Bug]: TypeScript types for driver.wait return single item instead of Array #14239

Open
@slhck

Description

@slhck

What happened?

I am using:

  • @types/selenium-webdriver: 4.1.24
  • selenium-webdriver: 4.22.0
  • typescript: 5.5.3

The TypeScript definition for webdriver.wait seems to be wrong or inconsistent.

In the below code snippet, I get an error:

Property 'length' does not exist on type 'WebElement'.ts(2339)

Yet, result is an array of WebElements:

> result.at(0)
WebElement {driver_: Driver, id_: Promise, log_: Logger}

Since driver.wait returns a WebElementPromise, it assumes it's only a single item, whereas the until.elementsLocated returns a Condition<WebElement[]>.

How can we reproduce the issue?

import webdriver, { By, until } from "selenium-webdriver";
import chrome from "selenium-webdriver/chrome.js";

const chromeOptions = new chrome.Options().addArguments(
  "--mute-audio",
  "--autoplay-policy=no-user-gesture-required"
);

const driver = new webdriver.Builder()
  .forBrowser("chrome")
  .setChromeOptions(chromeOptions)
  .build();

await driver.get("https://www.youtube.com");

const primaryBtnsPromise = driver.wait(
  until.elementsLocated(By.css("tp-yt-paper-button.style-primary"))
);
const rejectButtonPromise = driver.wait(
  until.elementsLocated(By.css('button[aria-label*="Reject"]'))
);

const result = await Promise.race([primaryBtnsPromise, rejectButtonPromise]);

console.log("result", Array.isArray(result)); // --> true!

if (result.length <= 0) {
  throw new Error(`No buttons found!`);
}

Relevant log output

See above

Operating System

N/A

Selenium version

4.22.0

What are the browser(s) and version(s) where you see this issue?

N/A

What are the browser driver(s) and version(s) where you see this issue?

N/A

Are you using Selenium Grid?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-nodejsJavaScript BindingsI-defectSomething is not working as intendedR-help wantedIssues looking for contributions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions