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

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

作者: 暖冬x | 来源:发表于2019-05-20 10:45 被阅读0次

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

相关文章

网友评论

      本文标题:自动化测试selenium页面滚动操作+SendKeys模拟键盘

      本文链接:https://www.haomeiwen.com/subject/fwvhzqtx.html