Open
Description
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 WebElement
s:
> 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