量角器不能单击元素但能够getText

时间:2015-04-03 17:00:28

标签: javascript protractor

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

这是我的代码:

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

                });
        });
};

所以这就是我尝试的一切

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>

2 个答案:

答案 0 :(得分:4)

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

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

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

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

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

您也可以采用不同的方法,并使用by.linkText定位器:

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

答案 1 :(得分:0)

如果没有任何效果,请尝试!

var element = element(by.css('.foo'));
browser.executeScript("arguments[0].click();", element.getWebElement());