其他分享
首页 > 其他分享> > Selenium缓慢拖动滚动条

Selenium缓慢拖动滚动条

作者:互联网

selenium自动化模拟的时候,有时候要模拟到拖动滚动条,所以放上代码啦~

下面代码是直接拉到底

for i in range(4, 9):
time.sleep(0.5)
driver.execute_script('window.scrollTo(0, document.body.scrollHeight)')
time.sleep(0.5)

下面代码是缓慢拖动

js = "return action=document.body.scrollHeight"
new_height = driver.execute_script(js)
for i in range(0,new_height,150):
driver.execute_script('window.scrollTo(0, %s)'%(i))

每次150的间距拖动。。不怎么会码字。敬请谅解

标签:execute,script,拖动,Selenium,driver,height,滚动条,scrollTo
来源: https://www.cnblogs.com/xiaojuntest/p/14263736.html