File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,14 @@ export class Condition<T> {
110110 * Defines a condition that will result in a {@link WebElement}.
111111 */
112112export class WebElementCondition extends Condition < WebElement > {
113+ /**
114+ * Private discriminator to prevent structural type compatibility with
115+ * Condition<WebElement[]>. This ensures TypeScript correctly resolves
116+ * driver.wait() overloads when using elementsLocated() vs elementLocated().
117+ * @see https://github.com/SeleniumHQ/selenium/issues/14239
118+ */
119+ private readonly __isWebElementCondition : true ;
120+
113121 /**
114122 * @param {string } message A descriptive error message. Should complete the
115123 * sentence "Waiting [...]"
Original file line number Diff line number Diff line change @@ -599,6 +599,29 @@ function TestUntilModule() {
599599 conditionWebElements = webdriver . until . elementsLocated ( webdriver . By . className ( "class" ) ) ;
600600}
601601
602+ // Test for https://github.com/SeleniumHQ/selenium/issues/14239
603+ // driver.wait(until.elementsLocated(...)) should return Promise<WebElement[]>, not WebElementPromise
604+ async function TestElementsLocatedReturnsArray ( ) {
605+ let driver : webdriver . WebDriver = new webdriver . Builder ( ) . withCapabilities ( webdriver . Capabilities . chrome ( ) ) . build ( ) ;
606+
607+ // elementsLocated should return Condition<WebElement[]>
608+ // driver.wait should correctly resolve this to Promise<WebElement[]>
609+ const elements : webdriver . WebElement [ ] = await driver . wait (
610+ webdriver . until . elementsLocated ( webdriver . By . css ( ".foo" ) ) ,
611+ ) ;
612+
613+ // These should compile - elements is an array
614+ const length : number = elements . length ;
615+ elements . forEach ( ( el : webdriver . WebElement ) => el . click ( ) ) ;
616+ const mapped : string [ ] = elements . map ( ( el : webdriver . WebElement ) => "test" ) ;
617+
618+ // elementLocated (singular) should still return WebElementPromise
619+ const singleElement : webdriver . WebElement = await driver . wait (
620+ webdriver . until . elementLocated ( webdriver . By . css ( ".foo" ) ) ,
621+ ) ;
622+ singleElement . click ( ) ;
623+ }
624+
602625function TestShadowRoot ( ) {
603626 let driver : webdriver . WebDriver = new webdriver . Builder ( ) . withCapabilities ( webdriver . Capabilities . chrome ( ) ) . build ( ) ;
604627
You can’t perform that action at this time.
0 commit comments