javascript - Selenium WebdriverJS Promise Loop -


i'm trying "more" link in container keep clicking on until link no longer there. i'm creating deferred , returning fulfill call happening once there no longer "more" link available.

.then(function (previousresults) {     var deferred = webdriver.promise.defer();      // more link, keep clicking till it's no longer available     browser.wait(function() {         // see if have "more" click on         browser.findelements(bymorelinkxpath)             .then(function (morelinks) {                 if (morelinks[0]) {                     console.log('has more');                     morelinks[0].click()                         .then(function() {                             // check spinner go away                             browser.wait(pagedoneloading, configsetting.settings.testtimeoutmillis);                         });                 } else {                     console.log('no more');                     deferred.fulfill(true);                 }             });     }, 5000);      return deferred.promise; }) 

unfortunately, promise never fulfilled times out. tried doing return deferred.promise; in else block , while works reject, still doesn't work fulfill.

the syntax of webdriver.wait:

wait(condition, opt_timeout, opt_message)

but in code, first argument neither condition nor promise function, change to:

also, think doing here promise anti-pattern( not seeing loop of checking again more links, sorry think not understand driver.wait ), reduce above function as:

function exhaustmorelinks(){     return driver.wait( until.elementlocated(bymorelinkxpath), 5000)         .then(function(){             return driver.findelement(bymorelinkxpath);         }).then(function(morelink){             console.log('more links');             return morelink.click();         }).then(function(){                 return browser.wait(pagedoneloading(), configsetting.settings.testtimeoutmillis).then(exhaustmorelinks);             }, function(err){             if(err.name === 'nosuchelementerror' || (err.message.search(/timed out/i)> -1 && err.message.search(/waiting element/i) > -1) ){    // checking if error because time-out or element not found, if true, redirect fulfil                 console.log('no more links');                 return;             }else{                 throw err;             }         }); } 

and usage like:

... .then(exhaustmorelinks) ... 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -