【问题标题】:How to get id value in protractor and use in if condition如何在量角器中获取 id 值并在 if 条件下使用
【发布时间】:2015-09-03 08:12:53
【问题描述】:

在我的项目中,我有代码:

<div class="slotMachineContainer" style="margin-top: -156px;">
    <div ng-repeat="game in GameModel" class="start-game-block-text ng-binding ng-scope" id="round_1_3">Speed Sort</div>
    <div ng-repeat="game in GameModel" class="start-game-block-text ng-binding ng-scope" id="round_1_0"></div>
    <div ng-repeat="game in GameModel" class="start-game-block-text ng-binding ng-scope" id="round_1_1">Rapid Fill-In-The-Blank</div>
    <div ng-repeat="game in GameModel" class="start-game-block-text ng-binding ng-scope" id="round_1_2">Lightning Swipe</div>
    <div ng-repeat="game in GameModel" class="start-game-block-text ng-binding ng-scope" id="round_1_3">Speed Sort</div>
    <div ng-repeat="game in GameModel" class="start-game-block-text ng-binding ng-scope" id="round_1_0"></div>
</div>

这实现了随机化。 我的问题是如何设置变量 id 的值,例如#round_1_3 或 div 标签之间的字符串&lt;div&gt;Speed Sort&lt;/div&gt; 也可以检查这些随机返回我的条件是否可以用来做量角器测试。我试过var element = (by.id ('# random_1_3')).getText (); 但没有用。 如果您有任何建议可以帮助我。谢谢

【问题讨论】:

    标签: javascript angularjs unit-testing protractor


    【解决方案1】:

    已经有多种定位器可用于量角器。对于您的情况,最简单的方法是使用by.id。但是,您的语法对我来说看起来不对。同样在量角器中,一切都返回一个承诺。所以为了让你使用它,你应该等待 promise 返回然后控制台记录它。这是它的一个样本-

    element(by.id('random_1_3')).getText().then(function(text){
        console.log(text);
    });
    

    More on Protractor locators。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      • 2021-08-14
      • 1970-01-01
      • 2017-03-15
      • 2016-03-08
      • 2019-09-19
      • 1970-01-01
      相关资源
      最近更新 更多