selenium滚动条

letheashura 2020-03-05

程序如下:

from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")
#拖动到滚动条底部---向下
js = "var q=document.documentElement.scrollTop=10000"
driver.execute_script(js)
sleep(3)
#滚动左右滚动条---向右
js2 = "var q=document.documentElement.scrollLeft=10000"
driver.execute_script(js2)
sleep(3)
#滚动左右滚动条---向左
js3 = "var q=document.documentElement.scrollLeft=0"
driver.execute_script(js3)

# #控制滚动条逐步滚动
# for y in range(15):
#     js = "window.scrollBy(0,100)"
#     driver.execute_script(js)
#     sleep(1)

相关推荐