自动化测试selenium页面滚动操作+SendKeys模拟键盘操作

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}")

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。