【问题标题】:Not able to click on mat-checkbox using protractor无法使用量角器单击 mat-checkbox
【发布时间】:2020-03-26 08:25:34
【问题描述】:

我正在尝试单击复选框,尤其是 mat-checkbox,但没有成功。

不管我用的是什么类型的定位器,结果都是:

“失败:使用定位器找不到元素:.....”

我能找到的其余页面元素。
我附上 html 和我的 spec.js 的一部分

html:

<mat-checkbox _ngcontent-xmg-c24="" class="checkbox mat-checkbox mat-accent ng-untouched ng-pristine ng-invalid" formcontrolname="acceptTerms" id="mat-checkbox-1">
  <label class="mat-checkbox-layout" for="mat-checkbox-1-input">
    <div class="mat-checkbox-inner-container mat-checkbox-inner-container-no-side-margin">
      <input class="mat-checkbox-input cdk-visually-hidden" type="checkbox" id="mat-checkbox-1-input" tabindex="0" aria-checked="false">
      <div class="mat-checkbox-ripple mat-ripple" matripple="">
        <div class="mat-ripple-element mat-checkbox-persistent-ripple">
        </div>
      </div>
      <div class="mat-checkbox-frame">
      </div>
      <div class="mat-checkbox-background">
        <svg xml:space="preserve" class="mat-checkbox-checkmark" focusable="false" version="1.1" viewBox="0 0 24 24">
          <path class="mat-checkbox-checkmark-path" d="M4.1,12.7 9,17.6 20.3,6.3" fill="none" stroke="white"></path>
        </svg>
        <div class="mat-checkbox-mixedmark">
        </div>
      </div>
    </div>
    <span class="mat-checkbox-label">
      <span style="display:none">&nbsp;
      </span>
    </span>
  </label>
</mat-checkbox>

spec.js

it('Registration', async function (){
    await homePage.clickRegistration();
    await registrationPage.fillEmailAddress(email);
    await registrationPage.fillPassword(password);
    await registrationPage.fillPassword2(password);
    let checkbox = element(by.css("input[formcontrolname=acceptTerms]"));
    expect(checkbox).toBeDefined();
    await browser.actions().mouseMove(checkbox).click().perform();
});

【问题讨论】:

    标签: angularjs protractor automated-tests


    【解决方案1】:

    你应该试试

    await checkbox.click();
    

    【讨论】:

    • 虽然这段代码可能会解决问题,但一个好的答案还应该解释它的作用以及它如何提供帮助?
    猜你喜欢
    • 2021-02-16
    • 1970-01-01
    • 1970-01-01
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    相关资源
    最近更新 更多