python-selenium,关于页面滑动的操作

 //移动到元素element对象的“顶端”与当前窗口的“顶部”对齐  
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);  
 ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);  
 //移动到元素element对象的“底端”与当前窗口的“底部”对齐  
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(false);", element);  

//移动到页面最底部  
 ((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");  

 //移动到指定的坐标(相对当前的坐标移动)  
((JavascriptExecutor) driver).executeScript("window.scrollBy(0, 700)");  
Thread.sleep(3000);  
//结合上面的scrollBy语句,相当于移动到700+800=1600像素位置  
 ((JavascriptExecutor) driver).executeScript("window.scrollBy(0, 800)");  

//移动到窗口绝对位置坐标,如下移动到纵坐标1600像素位置  
 ((JavascriptExecutor) driver).executeScript("window.scrollTo(0, 1600)");  
 Thread.sleep(3000);  
 //结合上面的scrollTo语句,仍然移动到纵坐标1200像素位置  
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, 1200)");  

  

第一种:

#滑到底部

js="var q=document.documentElement.scrollTop=100000"

driver.execut_script(js)

目前在firefox,chrome上验证都是可以跑通的

#滑动到顶部

js="var q=document.documentElement.scrollTop=0"

driver.execut_script(js)



第二种

#滑到底部

js="window.scrollTo(0,document.body.scrollHeight)"

driver.execute_script(js)

目前在firefox,chrome上验证都是可以跑通的

#滑动到顶部

js="window.scrollTo(0,0)"

driver.execute_script(js)



scrollHeight 获取对象的滚动高度。 
scrollLeft 设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离。 
scrollTop 设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离。 
scrollWidth 获取对象的滚动宽度。

  

原文地址:https://www.cnblogs.com/pythonClub/p/9830178.html