问题遇到的现象和发生背景 在使用selenium模拟登录12306时,滑块一枝滑动验证失败 - import time
- from selenium import webdriver
- from selenium.webdriver import ActionChains
- from selenium.webdriver.common.by import By
- # driver.get('https://www.baidu.com')
- # print(driver.page_source)
- driver=webdriver.Chrome()
- driver.get('https://kyfw.12306.cn/otn/resources/login.html')
- def denglu():
- driver.find_element(By.ID,'J-userName').send_keys('15037082591')
- driver.find_element(By.ID,'J-password').send_keys('j20161422010315')
- time.sleep(1)
- driver.find_element(By.ID,'J-login').click()
- huakuai()
- def huakuai():
- action=ActionChains(driver)
- while True:
- try:
- time.sleep(2)
- span=driver.find_element(By.XPATH,'//*[@id="nc_1_n1z"]')
- action.click_and_hold(span)
- for i in range(5):
- # perform()立即执行动作链
- # move-by-offset(x,y):水平方向竖直方向
- action.move_by_offset(60, 0).perform()
- # 释放动作链
- action.release()
- time.sleep(2)
- driver.find_element(By.XPATH,'//*[@id="nc_1_refresh1"]').click()
- except Exception as e:
- print(e)
- break
- if __name__ == '__main__':
- denglu()
-
-
-
-
复制代码运行结果及报错内容 我设置了一个循环,while try滑块验证不成功就重新滑动
我的解答思路和尝试过的方法我想要达到的结果
|