【发布时间】:2018-09-28 18:27:16
【问题描述】:
我见过这个用量角器获取所有属性的解决方案:
Get all element attributes using protractor
但我在 Angular 6 中使用 typescript,似乎无法使用上述方法对其进行扩展。
我正在做的是这样的:
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);
};
我收到以下错误:
Unhandled rejection TypeError: Cannot set property 'getAttributes' of undefined
Get 属性工作正常,但有以下消息:
W/element - more than one element found for locator By(css selector, #id) - the first result will be used
我仍然想坚持导入而不是切换到模块的 require。
如何解决此问题并使其适用于 Typescript?
【问题讨论】:
标签: javascript typescript selenium protractor