Selenium-测试对象操作之:浏览器滚动条
#encoding=utf-8
from selenium import webdriver
import time,os
driver = webdriver.Chrome()
#打开网页
driver.get('https://www.baidu.com/')
driver.maximize_window()
input_box = driver.find_element_by_id("kw").send_keys('selenium')
driver.find_element_by_id("su").click()
time.sleep(3)
# 将页面滚动条拖到底部
js = "var q=document.body.scrollTop=100000"
driver.execute_script(js)
time.sleep(3)
# 将滚动条移动到页面的顶部
js = "var q=document.body.scrollTop=0"
driver.execute_script(js)
time.sleep(3)
# 将滚动条移动到页面的任意位置
js = "var q=document.body.scrollTop=500"
driver.execute_script(js)
time.sleep(3)