This repository was archived by the owner on Jul 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -353,7 +353,23 @@ ElementArrayFinder.prototype.toElementFinder_ = function() {
353353 */
354354ElementArrayFinder . prototype . count = function ( ) {
355355 return this . getWebElements ( ) . then ( function ( arr ) {
356- return arr . length ;
356+ var list = arr . map ( function ( webElem ) {
357+ // Calling any method forces a staleness check
358+ return webElem . isEnabled ( ) . then ( function ( ) {
359+ return 1 ; // is present
360+ } , function ( err ) {
361+ if ( err . code == webdriver . error . ErrorCode . STALE_ELEMENT_REFERENCE ) {
362+ return 0 ; // not present
363+ } else {
364+ throw err ;
365+ }
366+ } ) ;
367+ } ) ;
368+ return webdriver . promise . all ( list ) . then ( function ( presenceArr ) {
369+ return presenceArr . reduce ( function ( acc , isPresent ) {
370+ return acc + isPresent ;
371+ } , 0 ) ;
372+ } ) ;
357373 } , function ( err ) {
358374 if ( err . code == webdriver . error . ErrorCode . NO_SUCH_ELEMENT ) {
359375 return 0 ;
Original file line number Diff line number Diff line change @@ -364,6 +364,17 @@ describe('ElementArrayFinder', function() {
364364 expect ( element . all ( by . binding ( 'doesnotexist' ) ) . count ( ) ) . toEqual ( 0 ) ;
365365 } ) ;
366366
367+ it ( 'should return not present when an element disappears within an array' ,
368+ function ( ) {
369+ browser . get ( 'index.html#/form' ) ;
370+ element . all ( by . model ( 'color' ) ) . then ( function ( elements ) {
371+ var disappearingElem = elements [ 0 ] ;
372+ expect ( disappearingElem . isPresent ( ) ) . toBeTruthy ( ) ;
373+ browser . get ( 'index.html#/bindings' ) ;
374+ expect ( disappearingElem . isPresent ( ) ) . toBeFalsy ( ) ;
375+ } ) ;
376+ } ) ;
377+
367378 it ( 'should get an element from an array' , function ( ) {
368379 var colorList = element . all ( by . model ( 'color' ) ) ;
369380
You can’t perform that action at this time.
0 commit comments