python 执行js 代码 滚动当前页面

    def scroll_until_loaded1(self):
        check_height = self.driver.execute_script("return document.body.scrollHeight;")

        js = r'''

            function a(h){
                var timer = null;
                
    
                timer = setInterval(function(){
                    console.log(document.body.scrollHeight)
                    console.log("h1 : " + h)
                    if (h<=document.body.scrollHeight) {
    
                        h = h + 100;
                        window.scrollTo(0, h);
                    }else{
                        
                        clearInterval(timer);
                        return true;
                    }
    
                },300)
                
            }
            a()

        '''
        self.driver.execute_script(js)

        try:
            self.wait.until(
                lambda driver: self.driver.execute_script(js))

        except TimeoutException:
           pass

 

posted @ 2019-12-23 09:14  shijiu520  阅读(296)  评论(0)    收藏  举报