0

I am trying to count the total elements of a recycler view in android appium using wd.js.

For this I am using the logic:

1.For the id get all elements displayed on the screen>>get each elements unique content description and save it to an array.

2.Swipe/scroll the screen>>save the element's unique attribute to the array>>while total length of the array is not equal to the total count

I have written below code for this:

it("Scroll and save offerid to offersPresent List", function () {
 while(offersPresent.length !== offersCount) {
 return offersPOM.swipeNew(driver, function (err, res) { }).then(function () {
 driver.elementsById('someId').then(function (els) {
 els.forEach(function (el) {
 el.getAttribute('contentDescription').then(function (offerId) {
 //Here I check if the offerId is already there in the array or not
 if (offersPresent.indexOf(offerId) === -1) {
 offersPresent.push(offerId);
 }
 console.log('offersPresent'.green, offersPresent);
 })
 })
 })
 })
 }
 });

The swipNew function is:

exports.swipeNew = function (driver, callback) {
 var action = new TouchAction(driver);
 action
 .press({ x: 17, y: 1500 })
 .wait(2000)
 .moveTo({ x: 17, y: 254 })
 .release();
 return action.perform().then(function (err, res) {
 return callback(err, res);
 })
};

The problem is no matter the condition, this loop only runs once. How to make this loop run till the while condition is satisfied?

asked Apr 13, 2017 at 12:41

1 Answer 1

0

The return function in Javascript will stop the while loop so it will only attempt the code in the while loop once.

Here is a another question that explains it in more detail: Javascript, while loop return

answered Apr 13, 2017 at 12:48
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.