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

编程入门 行业动态 更新时间:2024-10-28 16:16:20
本文介绍了量角器不能单击元素但能够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

本文发布于:2023-11-22 23:08:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619280.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:量角器   单击   元素   getText

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!