Protractor: Scroll down

后端 未结 9 465
有刺的猬
有刺的猬 2020-11-30 04:59

I have an button on my page that is visible when the user scrolls down. Because of this, protractor tests give me an error:

UnknownError: unknown erro

9条回答
  •  悲&欢浪女
    2020-11-30 05:16

    In case anyone else is having troubles like I was:

    I was trying to scroll to the bottom of the page to load my next set of data in an infinite scroll scenario. I tried different variations of window.scrollTo as well as arguments[0].click() with no success.

    Finally I realized, to get the page to scroll, I had to bring focus to the "window" by clicking on any element within the window. Then window.scrollTo(0, document.body.scrollHeight) worked liked a charm!

    example code:

    element(by.className('')).click();
    browser.executeScript('window.scrollTo(0,document.body.scrollHeight)').then(function(){
    //whatever you need to check for here
    });
    

提交回复
热议问题