JavaScript protractor wait for multiple objects protractor wait for multiple elements

i'm loading somthing like this in DOM using AJAX:

<div class="elm_class"></div>
<div class="elm_class"></div>
<div class="elm_class"></div>

and then I need to wait for n elements presents in my protractor test. My best try was:

function needTrue(css,i){
    e = element.all(by.css(css));
    var EC = protractor.ExpectedConditions;
    if(e.length>i){
        return EC.presenceOf($$(".heading-description.uplevel").get(m1I));
    }else{
        return setTimeout(needTrue(css,length),1000);
    }
}

browser.driver.wait(needTrue(".elm_class", 3) , 10000);

but it doesn't even work this way throwing error

maximum call stack size exceeded.

I would appreciate if someone could explain me how can I bring back to the wait function "promise" object.

Answer:1

browser.wait automatically loops up to the specified number of milliseconds until it returns true so you don't want to put a setTimeout inside it. Also you will want to use .count() not .length for the number of elements found by .all

function needTrue(css,i){
  e = element.all(by.css(css));

  // count the number of elements found
  return e.count().then(function(elementCount) {
    // if not enough elements, return false so browser.wait will keep looping
    return elementCount >== i;
  });
};

browser.driver.wait(needTrue(".elm_class", 3) , 10000);

// after waiting for the elements, check whatever
// I don't use EC, so I don't know if this part of the code actually works
var EC = protractor.ExpectedConditions;
expect(EC.presenceOf($$(".heading-description.uplevel").get(m1I))).toBe(true);
Answer:2

<p>1</p> <p>2</p> <p>3</p> I want to hide / delete the second <p> without using .eq(), or CSS nth-child(2), I just want to catch the value if it's 2 then ...

<p>1</p> <p>2</p> <p>3</p> I want to hide / delete the second <p> without using .eq(), or CSS nth-child(2), I just want to catch the value if it's 2 then ...

  1. selector based on text

I want to upload user uploaded file (from website <form>) to my FTP server, in which I want to bypass the server and want that file should be sent to FTP server directly. Is it possible using ...

I want to upload user uploaded file (from website <form>) to my FTP server, in which I want to bypass the server and want that file should be sent to FTP server directly. Is it possible using ...

  1. upload local file to s3
  2. upload local file to server ssh
  3. upload local file to spotify
  4. upload local file to s3 python
  5. upload local file to ec2
  6. upload local file to dbfs
  7. upload local file to s3 boto3
  8. upload local file to s3 aws cli
  9. upload local file to colab
  10. upload local file to databricks
  11. upload local file to ec2 instance
  12. upload local file to hdfs
  13. upload local file javascript
  14. upload local file to server
  15. upload local file to s3 bucket
  16. upload local file to jupyter notebook
  17. upload local file to github
  18. upload local file to azure blob
  19. upload local file to linux server
  20. upload local file to azure blob c#

I'm using an ajax call to append rows dynamically to a table using jQuery. I would like the button generated in each row to display a modal with data specific to the items in that particular row. I ...

I'm using an ajax call to append rows dynamically to a table using jQuery. I would like the button generated in each row to display a modal with data specific to the items in that particular row. I ...

  1. materialize modal initialize
  2. materialize modal

I need to upload an from a clients computer to the server running the code. It wouldn't be hard if those files were less than 2mb, but since the file may be a video as well, I'm not sure how to ...

I need to upload an from a clients computer to the server running the code. It wouldn't be hard if those files were less than 2mb, but since the file may be a video as well, I'm not sure how to ...

  1. upload file image php
  2. upload file image laravel
  3. upload file image html
  4. upload file image using ajax
  5. upload file image codeigniter
  6. upload file image javascript
  7. upload file image bootstrap
  8. upload file image
  9. upload file image jquery
  10. upload file image angular
  11. upload file image only
  12. upload file image react
  13. upload file image php mysql
  14. upload file image c#
  15. upload file image python
  16. upload file image icon
  17. upload file image angularjs
  18. upload file image type
  19. upload file image yii
  20. upload file image input