如何使用Protractor在页面上找到非唯一按钮

时间:2016-11-28 13:13:25

标签: javascript angularjs protractor gulp-protractor

我尝试找到HTML中没有唯一标识符的按钮。 我已经尝试过网络并访问网站上的多个网站,我仍然找不到有效的定位器。 页面上有三个按钮,我需要涂层的是页面上的第二个按钮。我已经尝试过了;

element.all(by.css('[type="button"]')).get(1).click();

element.(by.xpathy('//div [@ng-click="addAdminForm()"]')).click();

$$('[ng-click="addAdminForm()"]').click();

element.all(by.css('.adminportal-submit-button')).get(0).click();

在此先感谢,任何帮助将不胜感激。

<div class="layout-align-start-center layout-row flex">

<button class="md-primary adminportal-cancel-button md-button md-ink-ripple" ng-transclude="" type="button" ng-click="gotoHomePage()" ng-disabled="disableButtons" analytics-on="" analytics-category="Clinics" analytics-event="cancel" tabindex="0" aria-disabled="false">
</div>

<div class="layout-align-end-center layout-row">

<button class="md-raised md-primary adminportal-submit-button md-button md-ink-ripple" ng-transclude="" type="button" ng-click="addAdminForm()" ng-disabled="manageClinicForm.$invalid || disableButtons" analytics-on="" analytics-category="Clinic-Admins" analytics-event="register" tabindex="0" aria-disabled="false">

<button class="md-raised md-primary adminportal-submit-button md-button md-ink-ripple" ng-transclude="" type="submit" ng-disabled="manageClinicForm.$invalid || disableButtons" aria-disabled="false">

1 个答案:

答案 0 :(得分:0)

xpath的定位器应该可以工作:

element(by.xpath('//div[@ng-click="addAdminForm()"]')) 

如果没有,那么尝试使用等待:

var button = element(by.xpath('//div[@ng-click="addAdminForm()"]'));
 browser.wait(EC.presenceOf(element(by.xpath('//div[@ng-click="addAdminForm()"]'))), 30000).then(function () {
        browser.wait(EC.visibilityOf(element(by.xpath('//div[@ng-click="addAdminForm()"]'))), 30000).then(function () {
            browser.wait(EC.elementToBeClickable(element(by.xpath('//div[@ng-click="addAdminForm()"]'))), 30000).then(function () {
                button.click();
            });
        });
    });