动作链对象Day03-2

#!/usr/bin/env python
#coding: utf8
#python2
#Actions chains
#动作链对象,需要把driver驱动传给他
#动作链对象可以操作一系列设定好的行为
#滑块移动
from selenium import webdriver
from selenium.webdriver import ActionChains  # 破解滑动验证码的时候用的 可以拖动图片
from selenium.webdriver.common.by import By  # 按照什么方式查找,By.ID,By.CSS_SELECTOR
from selenium.webdriver.common.keys import Keys  # 键盘按键操作
from selenium.webdriver.support import expected_conditions as EC  # 和下面webdriverwait一起用的
from selenium.webdriver.support.wait import webdriverwait  # 等待页面加载某些元素
import time

driver = webdriver.Chrome(r'C:\Users\Administrator\Desktop\chromedriver.exe')
try:
    driver.implicitly_wait(10)
    driver.get('https://www.runoob.com/try/try.PHP?filename=jqueryui-api-droppable')
    time.sleep(5)

    #遗弃方法
    #driver.switch_to_frame()
    #新方法
    driver.switch_to.frame('iframeResult')
    time.sleep(1)

    #起始方法id:draggble
    source = driver.find_element_by_id('draggable')

    #目标方块id:droppable
    target = driver.find_element_by_id('droppable')

    print(source.size)#大小
    print(source.tag_name)#标签名
    print(source.text)#文本
    print(source.location)#坐标X与Y轴

    #找到滑动距离
    distance = target.location['x'] - source.location['x']

    #按住起始滑块
    ActionChains(driver).click_and_hold(source).perform()

    #方法二:一点一点移动
    s=0
    while s < distance:
        #获取动作链对象
        #每一次位移s距离
        ActionChains(driver).move_by_offset(xoffset=2,yoffset=0).perform()
        s+=2

        time.sleep(0.1)

    #释放起始滑块
    ActionChains(driver).release().perform()

    time.sleep(10)
finally:
    driver.close()

 

相关文章

转载地址:https://www.cnblogs.com/mini-monkey/p/12104821...
web自动化测试过程中页面截图相对比较简单,可以直接使用sel...
目录前言一、Selenium简介二、浏览器驱动1.浏览器驱动参考2....
一、iframe的含义:iframe是HTML中框架的一种形式,在对界面...
转载请注明出处❤️作者:测试蔡坨坨原文链接:caituotuo.to...
'''##**认识selenium**​**下载:pipinstall...