I came across this solution for fetching all attributes using protractor:
Get all element attributes using protractor
However, I am working with TypeScript and Angular 6 and struggling to implement the above method.
This is what I have tried so far:
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);
};
But I keep encountering the following error:
Unhandled rejection TypeError: Cannot set property 'getAttributes' of undefined
The get attribute functionality is working fine, but it displays the following message:
W/element - more than one element found for locator By(css selector, #id) - the first result will be used
I prefer sticking with imports rather than switching to require for modules. How can I resolve this issue and make it compatible with TypeScript?