KMC
KMC

Reputation: 1742

Protractor - Giving "could not find testability for element" error when accessing element

I'm running into issue with Protractor when accessing variable that stores return value of "elements.all". I'm fairly new to Protractor, so I wasn't sure how to select elements by custom attribute. Luckily, I received a suggestion, when I posted a question in another post. I was suggested to try out - "element.all(by.css('[mycustom-id]'));". But I'm not sure if that statement works or not since I'm getting "Could not find testability for element" error. It is also possible that I'm incorrectly iterating the object. I appreciate if anyone of you can point out my mistake. Thanks.

Spec.JS

var settings = require(__dirname + '/setting.json');
describe('Protractor Demo App', function() { 
    var target = element.all(by.css('[mycustom-id]')); 

    beforeEach(function() {
       browser.get(settings.url);
    });     

    it('Test mouseover', function() {       

       // This does not work
       target.each(function(item){
          //Do some stuff here
       });     

       // This does not work either
       target.count().then(function(x){
         console.log("Total--" + x);
       });
    });

});

index.html

<div>
    <a mycustom-id="123" href=''>HELLO1</a>
    <a mycustom-id="211" href=''>HELLO2</a>
</div>

Upvotes: 1

Views: 322

Answers (2)

KMC
KMC

Reputation: 1742

I'm getting this error because I need to set useAllAngular2AppRoots to true in config file. So if anyone having similar issue, make sure you have useAllAngular2AppRoots set to True.

Upvotes: 1

Gunderson
Gunderson

Reputation: 3268

It's not a good practice to put things outside of Jasmine functions, i.e. outside of it(), beforeAll() etc. Protractor uses those Jasmine functions to manage the control flow.

So I'm guessing that it is trying to create those webElements way before it should be. Move your element locator inside the it() block.

it('Test mouseover', function() {       
   var target = element.all(by.css('[mycustom-id]')); 
   target.each(function(item){
      //Do some stuff here
   });
});

Upvotes: 0

Related Questions