1、selenium 页面滚动操作:
//移动到元素element对象的“顶端”与当前窗口的“顶部”对齐
driver.execute_script("arguments[0].scrollIntoView();", element);
driver.execute_script("arguments[0].scrollIntoView(true);", element);
//移动到元素element对象的“底端”与当前窗口的“底部”对齐
driver.execute_script("arguments[0].scrollIntoView(false);", element);
//移动到页面最底部
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)");
//移动到指定的坐标(相对当前的坐标移动)
driver.execute_script("window.scrollBy(0, 700)");
self.driver.execute_script("arguments[0].scrollIntoView();", el) # 向下滑动滚动条,跳转到目标元素处
self.driver.execute_script("arguments[0].scrollIntoView(false);", el) # 向上滑动滚动条,跳转到目标元素处
2、SendKeys模拟键盘操作
1、例子:
import SendKeys
SendKeys.SendKeys("{ENTER}")
#2、模拟长按:
for i in range(10):
SendKeys.SendKeys("{ENTER}")