量角器不能单击元素但能够getText [英] protractor cannot click an element but able to getText

查看:82
本文介绍了量角器不能单击元素但能够getText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索结果页面,我正在尝试点击分页按钮。我可以通过转发器找到页面元素。我也能够获得单个页面元素的文本。但是当我点击页面按钮时,结果会有所不同,具体取决于我使用的点击方法。我尝试了各种click()方法但没有工作。我还能尝试什么?

I have a search results page where I'm trying to click on the pagination buttons. I'm able to locate page elements via repeater. I'm also able to get text of the individual page element. But when I click on the page button, the results are different depending on the click method I use. I tried all kinds of click() methods but none work. What else can I try?

这是我的代码:

this.clickPageNumber = function(pgNum) {
    browser.executeScript('window.scrollTo(254,1600);').then(function() {
                paginationPageNumberList.get(pgNum).then(function(we) {
                    browser.wait(EC.elementToBeClickable(we), 10000);
                    we.getText().then(function(pgText) { 
                        console.log('Clicking page: ' + pgText); //prints correct pg
                        we.click(); //this part doesn't work
                        browser.pause(); 
                    });

                });
        });
};

所以这里是我尝试的一切

so here is everything I tried

browser.actions().mouseMove(we).click(); //no error but pg does not paginate
we.sendKeys(protractor.Key.ENTER); //Error: Failed: unknown error : cannot focus element
we.click(); //rror: Failed: unknown error: Element is not clickable at point (254, 806). Other element would receive the click: <a href="" ng-click="selectPage(page - 1)" class="ng-binding">...</a>

这是html:

<div id="dispute-queue-search-result-pagination" class="pagination-controller">
<ul class="pagination ng-isolate-scope ng-valid" ng-change="resultController.pageChanged()" next-text="›" previous-text="‹" max-size="resultController.maxSize" ng-model="resultController.currentPage" items-per-page="resultController.itemsPerPage" total-items="resultController.totalItems">
<!-- ngIf: boundaryLinks -->
<!-- ngIf: directionLinks -->
<li class="ng-scope disabled" ng-class="{disabled: noPrevious()}" ng-if="directionLinks">
<a class="ng-binding" ng-click="selectPage(page - 1)" href="">‹</a>
</li>
<!-- end ngIf: directionLinks -->
<!-- ngRepeat: page in pages track by $index -->
<li class="ng-scope active" ng-class="{active: page.active}" ng-repeat="page in pages track by $index">
<a class="ng-binding" ng-click="selectPage(page.number)" href="">1</a>
</li>
<!-- end ngRepeat: page in pages track by $index -->
<li class="ng-scope" ng-class="{active: page.active}" ng-repeat="page in pages track by $index">
<a class="ng-binding" ng-click="selectPage(page.number)" href="">2</a>
</li>
<!-- end ngRepeat: page in pages track by $index -->
<li class="ng-scope" ng-class="{active: page.active}" ng-repeat="page in pages track by $index">
<a class="ng-binding" ng-click="selectPage(page.number)" href="">3</a>
</li>
<!-- end ngRepeat: page in pages track by $index -->
<li class="ng-scope" ng-class="{active: page.active}" ng-repeat="page in pages track by $index">
<a class="ng-binding" ng-click="selectPage(page.number)" href="">4</a>
</li>
<!-- end ngRepeat: page in pages track by $index -->
<li class="ng-scope" ng-class="{active: page.active}" ng-repeat="page in pages track by $index">
<a class="ng-binding" ng-click="selectPage(page.number)" href="">5</a>
</li>
<!-- end ngRepeat: page in pages track by $index -->
<!-- ngIf: directionLinks -->
<li class="ng-scope" ng-class="{disabled: noNext()}" ng-if="directionLinks">
<a class="ng-binding" ng-click="selectPage(page + 1)" href="">›</a>
</li>
<!-- end ngIf: directionLinks -->
<!-- ngIf: boundaryLinks -->
</ul>
</div>


推荐答案

对于repeater找到的每个元素,您需要点击 a 元素:

For every element found by repeater, you need to click the a element:

paginationPageNumberList.get(pgNum).element(by.tagName("a")).click();

或者如果您想等待它可点击:

Or in case you want to wait for it to be clickable:

var link = paginationPageNumberList.get(pgNum).element(by.tagName("a"));

browser.wait(EC.elementToBeClickable(link), 10000);
link.click();






你也可以采用不同的方法来处理它并使用 by.linkText locator:

this.clickPageNumber = function(pgNum) {
    browser.executeScript('window.scrollTo(254,1600);').then(function() {
        var link = element(by.css("ul.pagination")).element(by.linkText(pgNum.toString()));
        link.click();
    });
};

这篇关于量角器不能单击元素但能够getText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆