滚动到量角器中的第一个ng-repeat元素,然后单击

时间:2017-12-26 07:05:01

标签: protractor

滚动位于页面底部,当我尝试单击第一个元素时显示此错误:

  

错误:ElementNotVisibleError:元素不可见(会话信息:   chrome = 63.0.3239.84)(司机信息:chromedriver = 2.34.522913   (36222509aa6e819815938cbf2709b4849735537c),平台= Linux的   3.13.0-137-generic x86_64)

代码

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swiperefresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
      <!--Child View-->
    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.v4.widget.SwipeRefreshLayout>

1 个答案:

答案 0 :(得分:0)

你应该可以使用两种方式滚动它,既可以是JavaScript,也可以通过量角器方法browser.executeScript执行它们,然后继续使用量角器代码。

要小心,因为所有的量角器方法,甚至executeScript都会返回一个承诺,所以正确链接它。

我个人更喜欢的一般解决方案是使用scrollIntoView()方法。

browser.executeScript('document.querySelector("a selector of your element or of your ng-repeater block or whatever identifies your element").scrollIntoView()').then(() => element(by.repeater('item in arr').row(1)).click());

您的特定解决方案(意味着滚动到页面顶部)是scrollTo()方法。

browser.executeScript('window.scrollTo(0, 0);').then(() => element(by.repeater('item in arr').row(1)).click());
相关问题