【问题标题】:Get all element attributes using protractor with Typescript?使用带有 Typescript 的量角器获取所有元素属性?
【发布时间】: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


    【解决方案1】:

    在这里,您可以看到对您的问题以及如何解决问题的详细说明。 https://stackoverflow.com/a/27824315/10413416

    关于消息:

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

    您的定位器似乎找到了多个元素,并且它使用了第一个索引,也就是找到的第一个元素。 您可以创建更具体的定位器以将找到的元素限制为 1。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 2021-04-17
      • 2020-04-11
      相关资源
      最近更新 更多