### 动作链
```python
# 模拟鼠标点住,拖动的效果,实现滑块认证
# 两种形式
# -形式一:
# actions=ActionChains(bro) #拿到动作链对象
# actions.drag_and_drop(sourse,target) #把动作放到动作链中,准备串行执行
# actions.perform()
# -方式二:
# ActionChains(bro).click_and_hold(sourse).perform()
# distance=target.location['x']-sourse.location['x']
# track=0
# while track < distance:
# ActionChains(bro).move_by_offset(xoffset=2,yoffset=0).perform()
# track+=2
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait # 等待页面加载某些元素
import time
from selenium.webdriver.common.by import By
browser = webdriver.Chrome()
browser.get('http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable')
browser.implicitly_wait(10)
browser.maximize_window()
try:
browser.switch_to.frame('iframeResult')
sourse = browser.find_element(By.ID, 'draggable')
target = browser.find_element(By.ID, 'droppable')
# 方式一:基于同一个动作链串行执行
# action = ActionChains(browser)
# action.drag_and_drop(sourse, target)
# action.perform()
# 方式二:不同的动作链,每次移动的位移都不同
ActionChains(browser).click_and_hold(sourse).perform()# 鼠标点中源 标签 不松开
distance=target.location['x']-sourse.location['x']
track=0
while track<distance:
ActionChains(browser).move_by_offset(xoffset=2,yoffset=0).perform()
track+=2
ActionChains(browser).release().perform()
time.sleep(3)
finally:
browser.close()
标签:sourse,target,动作,ActionChains,track,import,browser
From: https://www.cnblogs.com/liyuanxiangls/p/17545597.html