问题描述:
在测试中我们可能会遇到向上滑和向下滑的随机操作,比如一个文章的长短导致了页面的长短不通,会需要上滑才可以看到文章的内容。
文章源自玩技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刷新页面即可查看