1

I have seen this solution for getting all attributes with protractor:

Get all element attributes using protractor

But I am using typescript with Angular 6 and cannot seem to extend it with the above method.

What I am doing is this:

import {browser, by, element} from 'protractor';
element.prototype.getAttributes = function () {
  return (function (node) {
    let attrs = {};
    for (let i = 0; i < node.length; i++) {
      attrs[node.item(i).name] = node.item(i).value;
    }
    return attrs;
  })(this.attributes);
};

And I am getting the following error:

Unhandled rejection TypeError: Cannot set property 'getAttributes' of undefined

Get attribute works fine, but has the following message:

W/element - more than one element found for locator By(css selector, #id) - the first result will be used

I would still like to stick with imports rather than switching to require for modules.

How can I fix this and make it work for Typescript?

apollowebdesigns
  • 658
  • 11
  • 26

1 Answers1

0

Here you can see a good explanation of your issue and how to resolve it. https://stackoverflow.com/a/27824315/10413416

About the message:

W/element - more than one element found for locator By(css selector, #id) - the first result will be used

Seems your locator is finding more than 1 element and its using the first index a.k.a first element found. You can create more specific locator to limit the found elements to 1.

Infern0
  • 2,565
  • 1
  • 8
  • 21