selenium之动作链

 

  概念:一组连续的行为动作

  爬取网站:https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable

  背景:把左边的方块横竖往下便宜17px

  

from selenium import webdriver
from time import sleep
from selenium.webdriver import ActionChains #动作链
#实例化一个浏览器对象
bro = webdriver.Chrome(executable_path='./chromedriver.exe')

bro.get('https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable')

sleep(2)

#如果定位的标签是存在于iframe标签之中,在定位前必须先执行以下操作
bro.switch_to.frame('iframeResult')

div_tag = bro.find_element_by_xpath('//*[@id="draggable"]')


print(div_tag)
#实例化一个动作链对象,且将该对象链应用到当前的页面中
action = ActionChains(bro)

action.click_and_hold(div_tag)


for i in range(1,6):
    #action.move_by_offset(17,17).perform() #表示立即执行动作链
    action.move_by_offset(17,17).perform()
    sleep(0.5)

sleep(2)
bro.quit()

 

 

  

posted @ 2019-10-23 11:14  ivy_wang  阅读(263)  评论(0编辑  收藏  举报