Get binding element for 'ng-src' does not work, Protractor

In the Angular Phone cat application (step 10), I cannot use element(by.binding('bindingName')) Crawler Locators

Tutorial link : Angular mobile app (step 10, test)

More details

// Working
expect(element(by.css('img.phone')).getAttribute('src'))
  .toMatch(/img\/phones\/nexus-s.0.jpg/);

// Not Working
expect(element(by.binding('mainImageUrl')).getAttribute('src'))
  .toMatch(/img\/phones\/nexus-s.0.jpg/);
<img ng-src="{{mainImageUrl}}" class="phone">
Run codeHide result
+4
source share
3 answers

by.bindingwill not work in this case by definition .

According to the source code, it will only correspond to the element, if at least there is a class ng-bindingfor the element.

+4
source

alecx. {{ }} ,

:

<p class="phone">{{someText}}</p>

:

element(by.binding('someText'))

, ng, Angular. , , , ng-binding Angular, .

+2

, - , .:) , ng-bind value . ( , getText() : D)

..
  <img ng-src="{{mainImageUrl}}" class="phone">
  <input type="hidden" ng-bind="mainImageUrl" value="{{mainImageUrl}}">
..

javascript:

    element(by.binding('mainImageUrl')).getAttribute('value')
       .then(function(text){
          expect(text.toMatch(/img\/phones\/nexus-s.0.jpg/));
       });
0

All Articles