Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor find element with multiple div condition in AngularJS

I am trying to get list of items by checking multiple condition, example want to get file count

Example if I run below code, I get result 6:

element.all(by.repeater('releasenotefile in release.releasenotefiles')).count().then(function(count) {
      console.log(count);
});

But I want count of Release 1.4 only and I tried the code below, and it returns 0:

element.all(by.cssContainingText('.list_subhead',"1.04 Release Title")).all(by.repeater('releasenotefile in release.releasenotefiles')).count().then(function(count) {
                  console.log(count);
});

Here is my div structure:

------------
Release 1.4 <div class="accordion-section panel clearfix ng-scope" ng-repeat="release in app.releases" ng-class="{active: $first}">

Release note <div class="vz_list_container_01">

    File 1 <li class="bp ng-scope" ng-repeat="releasenotefile in release.releasenotefiles">
    File 2 
--------------

------------
Release 1.3

Release note

    File 3

--------------

------------
Release 1.2

Release note
    File 4 
    File 5
    File 6 
--------------
like image 918
Rayees Namathponnan Avatar asked Aug 23 '26 05:08

Rayees Namathponnan


1 Answers

I would get everything by repeater and use filter()+evaluate() to filter out results for release 1.4 only:

element.all(by.repeater('releasenotefile in release.releasenotefiles')).filter(function (elm) {
    return elm.evaluate("release").then(function (release) {
        return release.number === "1.4";
    });
});

Note that, for the sake of an example, I'm assuming release.number variable in scope is a release version number - check what variable in the scope is responsible for keeping the release version number.

like image 157
alecxe Avatar answered Aug 24 '26 20:08

alecxe