selenium 动作链

from selenium import webdriver
from lxml import etree
import time

a = webdriver.Chrome(executable_path=r'D:\python学习\其他\chromedriver.exe')
url = 'https://qzone.qq.com'
a.get(url)

# 定位快捷登录标签


# 如果标签存在 iframe中,进行标签定位前要执行一个 switch_to 操作
a.switch_to.frame('login_frame')
k = a.find_element_by_id('switcher_plogin')
k.click()
time.sleep(1)

# 输入账号密码
u = a.find_element_by_id('u')
u.send_keys('1238942283')
p = a.find_element_by_id('p')
p.send_keys('123456')

# 点击登录
btn = a.find_element_by_id('login_button')
btn.click()
time.sleep(1)


# 如果标签存在 iframe中,进行标签定位前要执行一个 switch_to 操作
a.switch_to.frame('tcaptcha_iframe')
move = a.find_element_by_id('tcaptcha_drag_thumb')

# 实例化动作链对象
action = webdriver.ActionChains(a)
action.click_and_hold(move)
time.sleep(2)
for i in range(10):
action.move_by_offset(26, 0).perform()
time.sleep(0.3)


action.release() # 释放移动

posted @ 2020-04-01 14:23  我会飞︿( ̄︶ ̄)︿  阅读(155)  评论(0编辑  收藏  举报