如何使用量角器打字稿

时间:2018-12-19 09:25:14

标签: angular typescript jasmine protractor webautomation

enter image description here

在创建量角器打字稿代码时需要您的帮助,如何单击此按钮之一?它具有_ngcontent类和span类,有人知道如何执行此操作吗?该网站上的代码是:

<form _ngcontent-c34 novalidate class="ng-untouched ng-unreal ng-valid">
    <atx-create-license-act-main _ngcontent-c34 _nghost-c36>
       <button _ngcontent-c36 color="accent" mat-raised-button class="mat-raised-button mat-accent">
           <span class="mat-button-wrapper">Add License</span>
           <div class="mat-button-droped mat-droped" matdrop></div>
           <div class="mat-button-focus-overlay"></div>
        </button>
    </atx-create-license-act-main>
</form>
<form _ngcontent-c34 novalidate class="ng-untouched ng-unreal ng-valid">
    <atx-create-license-act-main _ngcontent-c34 _nghost-c36>
       <button _ngcontent-c36 color="accent" mat-raised-button class="mat-raised-button mat-accent">
           <span class="mat-button-wrapper">Add License</span>
           <div class="mat-button-droped mat-droped" matdrop></div>
           <div class="mat-button-focus-overlay"></div>
        </button>
    </atx-create-license-act-main>
</form>

我已经在下面尝试了以下代码,但似乎无法正常工作...

clickdone = element.all(by.cssContainingText('.mat-button-wrapper','Add License')).get(0);
clickdone = element.all(by.css('button.mat-raised-button.mat-accent')).get(1);
clickdone = element(by.cssContainingText('span.mat-button-wrapper','Add License'));
clickdone = element.all(by.cssContainingText('button.mat-raised-button.mat-accent','Add License')).get(0);

然后执行...

clickdone.click();

它们似乎都不起作用。并且出现错误消息。“失败:元素不可交互”。 这是什么意思?我坚持了这个,知道怎么做吗?

1 个答案:

答案 0 :(得分:0)

尝试以下一项

addLicense = element.all(by.css('button>span.mat-button-wrapper');

browser.wait(protractor.ExpectedConditions.elementToBeClickable(addLicense.get(0)), 5000); 
addLicense.get(0).click();

根据您要单击的按钮更改索引。

希望它对您有帮助