selenium web页面滚动滚动条

#coding=utf-8
from selenium import webdriver
import  time


driver = webdriver.Safari()
driver.set_page_load_timeout(10)
driver.get('https://www.baidu.com/')
driver.maximize_window()

driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(3)
js = "var c=document.body.scrollTop=100000"
driver.execute_script(js)
time.sleep(6)
driver.quit()

第二种:
#coding=utf-8
from selenium import webdriver
import time

driver = webdriver.Safari()
driver.set_page_load_timeout(10)
driver.get('https://www.baidu.com/')
driver.maximize_window()

driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(3)
driver.execute_script("window.scrollTo(0,100000)")
time.sleep(6)
driver.quit()

Leave a Reply

Your email address will not be published.