【问题标题】:Protractor not able to identify the angularjs button using locator by.partialButtonText or by.buttontext量角器无法使用定位器 by.partialButtonText 或 by.buttontext 识别 angularjs 按钮
【发布时间】:2016-05-06 18:42:07
【问题描述】:

Angularjs 对象属性

<button class="btn ng-binding" data-ng-click="v.icle(vehidForm.$valid);" tabindex="0"> Continue </button>

用于识别对象的代码

element(by.buttonText("Continue"));

or 

element(by.partialButtonText("Continue"));

【问题讨论】:

    标签: javascript angularjs node.js protractor


    【解决方案1】:

    这些是猜测,但可以尝试以下方法:

    • 使用by.xpath locator:

      element(by.xpath("//button[contains(., 'Continue')]"));
      
    • 改为检查 data-ng-click 值:

      $('button[data-ng-click="vm.addVehicle(vehicleAddForm.$valid);‌"]');
      $('button[data-ng-click*=addVehicle]');
      
    • 等待按钮to be present

      var elm = element(by.partialButtonText("Continue"));
      var EC = protractor.ExpectedConditions;
      
      browser.wait(EC.presenceOf(elm), 5000);
      
      elm.click();
      

    【讨论】:

    • 是的,我可以使用 element(by.xpath('//button[@data-ng-click="vm.addVehicle(vehicleAddForm.$valid);"]')) 来识别它。点击();但我想知道为什么它不使用特定角度的定位器进行识别,例如 element(by.buttonText("Continue"));
    • @DilipReddy 好的,然后我会使用$('button[data-ng-click*=addVehicle]'); - 更简洁易读。
    • @DilipReddy 错误说明了什么?您也可能在您的应用中有多个“继续”按钮,并尝试选择错误的一个,只要第一个收到点击
    • 是的,应用程序有多个“继续”按钮,它不会在没有点击该页面中的按钮的同时抛出任何错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    相关资源
    最近更新 更多