zoukankan      html  css  js  c++  java
  • 动作链ActionChains

    from selenium import webdriver
    from selenium.webdriver import ActionChains
    
    from selenium.webdriver.support.wait import WebDriverWait  # 等待页面加载某些元素
    import time
    
    driver = webdriver.Chrome()
    driver.get('http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable')
    wait = WebDriverWait(driver, 3)
    # driver.implicitly_wait(3)  # 使用隐式等待
    
    try:
        driver.switch_to.frame('iframeResult')  # 切换到iframeResult
        sourse = driver.find_element_by_id('draggable')
        target = driver.find_element_by_id('droppable')
    
        # 方式一:基于同一个动作链串行执行
        # actions=ActionChains(driver) #拿到动作链对象
        # actions.drag_and_drop(sourse,target) #把动作放到动作链中,准备串行执行
        # actions.perform()
    
        # 方式二:不同的动作链,每次移动的位移都不同
    
        ActionChains(driver).click_and_hold(sourse).perform()
        distance = target.location['x'] - sourse.location['x']
    
        track = 0
        while track < distance:
            ActionChains(driver).move_by_offset(xoffset=2, yoffset=0).perform()
    
            # ActionChains(driver).move_by_offset()  # 移动x轴和y轴的距离
            # ActionChains(driver).move_to_element()  # 直接移动到某个控件上
            # ActionChains(driver).move_to_element_with_offset()  # 移动到某个控件的某个位置
            # 所有的动作最后都要执行perform(),真正的去执行
            track += 2
        
        # 释放动作链
        ActionChains(driver).release().perform()
    
        time.sleep(10)
    
    finally:
        driver.close()
  • 相关阅读:
    function 基础运用
    js基础知识2
    JavaScript的一些基础知识
    CSS3中2D3D转换、过渡、动画总结
    css的一些基础属性
    响应式布局和移动端开发
    css3动画
    美化盒子以及bootstrap的简单了解
    利用JS的双重for循环实现九九乘法表
    js练习:金字塔正星星与倒星星
  • 原文地址:https://www.cnblogs.com/ZhZhang12138/p/14885705.html
Copyright © 2011-2022 走看看