如何模拟web页面的上划和下滑的操作原创文章

玩技站长
玩技站长
管理员, Keymaster
11201
文章
0
粉丝
Auto测试评论357字数 296阅读0分59秒阅读模式
问题描述:

在测试中我们可能会遇到向上滑和向下滑的随机操作,比如一个文章的长短导致了页面的长短不通,会需要上滑才可以看到文章的内容。

如何模拟web页面的上划和下滑的操作插图文章源自玩技e族-https://www.playezu.com/761486.html

实现方式:(python+selenium)

第一步:我们使用selenium中的ActionChains来模拟键盘的PGUP和PGDN按键来实现(下滑)文章源自玩技e族-https://www.playezu.com/761486.html

actions = ActionChains(driver) 
actions.send_keys(Keys.PAGE_DOWN).perform()

第二步:添加随机数文章源自玩技e族-https://www.playezu.com/761486.html

# 记录滑动次数的变量 
scroll_count = 0 
# 随机滚动2-3次 
scroll_times = random.randint(2, 3)

第三步:我们使用selenium中的ActionChains来模拟键盘的PGUP和PGDN按键来实现(上滑)文章源自玩技e族-https://www.playezu.com/761486.html

actions = ActionChains(driver) 
actions.send_keys(Keys.PAGE_UP).perform()

第四步:完整代码展示文章源自玩技e族-https://www.playezu.com/761486.html

评论后查看
原创不易此内容为****隐藏内容****评论后,F5或Ctrl+F5刷新页面即可查看
文章源自玩技e族-https://www.playezu.com/761486.html文章源自玩技e族-https://www.playezu.com/761486.html
 
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证