如何使用 Protractor typescript 在具有跨度的按钮上单击具有相似元素详细信息的元素

how to click element with similar element details on button with span using Protractor typescript

需要您帮助创建量角器打字稿代码,如何单击此按钮之一?它有 _ngcontent class 和 span class,有没有人知道如何做到这一点?网站上的代码是:

<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();

none 似乎有效.. 错误提示.. "Failed: element not interactable"。 这是什么意思?我坚持这个,知道怎么做吗?

试试下面的

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

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

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

希望对你有帮助