我试图单击以选中复选框,特别是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">
</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();
});
您应该尝试
await checkbox.click();