from selenium import webdriver
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
driver.get('https://mail.qq.com/')
sleep(0.4)
driver.switch_to.frame('login_frame')
driver.find_element_by_id('u').send_keys('785214563')
sleep(0.4)
driver.find_element_by_id('p').send_keys('1020300.0')
sleep(0.4)
WebDriverWait(driver,10).until(ec.element_to_be_clickable((By.ID,"login_button")))
driver.find_element_by_id('login_button').click()
sleep(1)
driver.switch_to.frame('tcaptcha_iframe')
sleep(0.4)
#拖动滑块
while True:
slider = WebDriverWait(driver,20).until(ec.element_to_be_clickable((By.ID,'tcaptcha_drag_thumb')))
distance = 175
actions = webdriver.ActionChains(driver)
#点击开始拖拽
actions.click_and_hold(slider)
actions.pause(0.2)
actions.move_by_offset(distance+5,0)
sleep(0.2)
actions.move_by_offset(-10, 0)
actions.release()
actions.perform()
sleep(2)
try:
shuaxin = WebDriverWait(driver,1).until(ec.presence_of_element_located((By.CLASS_NAME,"tcaptcha-embed-contrl show-reload")))
driver.find_element_class_name("tcaptcha-embed-contrl show-reload").click()
except:
driver.quit()
break
|