#!/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()
动作链对象Day03-2
猜你喜欢
转载自www.cnblogs.com/zxdhahaha/p/11128254.html
今日推荐
周排行