Scrolling with phantomJs Selenium

本小妞迷上赌 提交于 2019-12-04 14:24:07

Got the answer, I called an explicit wait. and it works fine

public synchronized WebDriver scrollToBottom(WebDriver driver, WebElement element,int time) throws InterruptedException {
     String oldpage="";
     String newpage="";


     do{
         oldpage=driver.getPageSource();
         ((JavascriptExecutor) driver)
                .executeScript("window.scrollTo(0, (document.body.scrollHeight))");
         this.wait(time);
         newpage=driver.getPageSource();
    }while(!oldpage.equals(newpage));
        return driver;
    }

LinkedIn is changing the page when you scroll to the bottom, requesting more data. That means you never get the same result after the scrolling.

I'm not sure why you don't see in Firefox; maybe it handles the scroll event after you call getPageSource() or getPageSource() returns stale data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!