python爬蟲實踐——滑動登陸驗證


 1 from selenium import webdriver
 2 from selenium.webdriver import ActionChains
 3 import time
 4 
 5 driver=webdriver.Chrome()
 6 driver.implicitly_wait(10)
 7 driver.get('http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable')
 8 
 9 try:
10     # 切換到id為iframeResult的窗口內
11     driver.switch_to.frame('iframeResult')
12 
13     #源位置
14     draggable=driver.find_element_by_id('draggable')
15 
16     #目的位置
17     droppable=driver.find_element_by_id('droppable')
18     # 調用ActionChains,必須把驅動對象進去
19     actions=ActionChains(driver)
20 
21     # #方式一
22     # # 瞬間把源圖片位置秒移到目標圖片位置
23     # actions.drag_and_drop(draggable,droppable)
24     # #執行編輯好的行為
25     # actions.perform()
26     # time.sleep(5)
27 
28     #方式二
29     source=draggable.location['x']
30     target=droppable.location['x']
31     print(source,target)
32 
33     distance=target-source
34     print(distance)
35 
36     ActionChains(driver).click_and_hold(draggable).perform()
37     s=0
38     while s<distance:
39         ActionChains(driver).move_by_offset(xoffset=2,yoffset=0).perform()
40         s+=2
41 
42     ActionChains(driver).release().perform()
43     time.sleep(10)
44 
45 finally:
46     driver.close()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM