【问题标题】:Unable to locate elements within ng-repeat-start loop using protractor无法使用量角器在 ng-repeat-start 循环中定位元素
【发布时间】:2017-12-11 17:50:02
【问题描述】:

我无法使用量角器 5.2.0(节点 8.4.0,角度 1.5)在 ng-repeat 循环中定位元素。 UI 代码如下所示:

<tr ng-repeat-start="app in appsData.result" class="bordered"> 
<td>
<md-button id="{{app.name}}" class="md-raised primary" ng-click="appAction('configure', app)">
Configure and Run 
</md-button> 
</td>
</tr> 
<tr ng-repeat-end ng-show="expanded" ng-class="{'highlighted': expanded}">

..... 我试过了

var rows = element.all(by.repeater("app in appsData.result"));
rows.first().element(by.tagName("button")).getText().then(function(text){
console.log("Text: "+text);
});

但我得到了一个

[12:24:40] E/launcher - NoSuchElementError:索引超出范围。试 访问索引处的元素:0,但只有 0 个元素 匹配定位器 by.repeater("app in appsData.result")

(我也试过 tagName = md-button)

我做了一个 browser.getPageSource() 但我只看到

<tbody>
<!-- ngRepeat: app in appsData.result -->
</tbody>

我是量角器的新手,任何帮助将不胜感激!

我的量角器配置文件如下所示:

exports.config = {
  seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
  getPageTimeout: 600000,
  allScriptsTimeout: 5000000,
  framework: 'custom',
  // path relative to the current config file
  frameworkPath: require.resolve('protractor-cucumber-framework'),
  capabilities: {
    browserName: 'chrome',
    'chromeOptions': {
      args: ['--no-sandbox', 'headless']
    }
  },

  // Spec patterns are relative to this directory.
  specs: [
    'features/*.feature'
  ],

  baseURL: 'http://localhost:8080/',

  cucumberOpts: {
    require: 'features/step_definitions/*.js',
    tags: false,
    format: 'pretty',
    profile: false,
    'no-source': true
  }
};

【问题讨论】:

    标签: angularjs protractor


    【解决方案1】:

    如果 class="bordered" 是唯一的,可以试试:

    var rows = element.all(by.css('[class="bordered"]'));
    rows.first().element(by.css('md-button')).getText().then(function(text){
        console.log("Text: "+text);
    });
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      试试这个:

      var rows = element.all(by.css('[class="bordered"]'));
      rows.first().element(by.css('md-raised.primary')).getText().then(function(text){
      console.log("Text: "+text);
      });
      

      如果这不起作用,您也可以通过 xpath 或类名进行选择:

      element(by.className("md-raised primary"))
      

      【讨论】:

      • 谢谢。不幸的是,这两种方法都不起作用。我得到一个 [12:21:54] E/launcher - Index out of bound。尝试访问索引处的元素:0,但只有 0 个元素匹配定位器 By(css 选择器,[class="bordered"]) [12:21:54] E/launcher - NoSuchElementError: Index out of bound。试图访问 index: 0 处的元素,但只有 0 个元素匹配定位器 By(css selector, [class="bordered"])
      猜你喜欢
      • 1970-01-01
      • 2012-07-12
      • 2020-07-05
      • 2016-05-02
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多