我选取 https://www.helloweba.net/demo/2017/unlock/ 这个网站为例
# 目标:滑动滑块
# 1.定位按钮
# 2.按住滑块
# 3.滑块滑动
import time
from selenium import webdriver
# 创建一个浏览器对象
chrome_obj = webdriver.Chrome()
# 发送请求
chrome_obj.get('https://www.helloweba.net/demo/2017/unlock/')
# 1.定位滑块按钮
short_obj = chrome_obj.find_element_by_xpath('//div[@class="bar1 bar"]/div[@class="slide-to-unlock-handle"]')
# 2.按住
# 创建一个动作链对象,参数就是浏览器对象
action_obj = webdriver.ActionChains(chrome_obj)
# 点击并且按住,参数就是定位的按钮
action_obj.click_and_hold(short_obj)
# 定位整条滑块
long_obj = chrome_obj.find_element_by_xpath('//div[@class="bar1 bar"]/div[@class="slide-to-unlock-bg"]')
# 得到宽高
size_ = long_obj.size
width_ = size_['width']
# 3.定位滑动坐标
action_obj.move_by_offset(width_,0).perform()
# 4.松开滑动
action_obj.release()
time.sleep(3)