python模拟滑动滑块验证

    def get_tracks(self, distance):
        """
        根据偏移量获取移动轨迹
        :param distance:偏移量
        :return:移动轨迹
        """
        # 移动轨迹
        tracks = []
        # 当前位移
        current = 0
        # 减速阈值
        mid = distance * 4 / 5
        # 计算间隔
        t = 0.2
        # 初速度
        v = 0
        while current < distance:
            if current < mid:
                # 加速度为正2
                a = 5
            else:
                # 加速度为负3
                a = -3
            # 初速度v0
            v0 = v
            # 当前速度
            v = v0 + a * t
            # 移动距离
            move = v0 * t + 1 / 2 * a * t * t
            # 当前位移
            current += move
            # 加入轨迹
            tracks.append(round(move))
        return tracks

    def move_to_gap(self, slider, tracks):
        """
        拖动滑块
        :param slider: 滑块
        :param tracks: 轨迹
        :return:
        """
        # 模拟滑动滑块
        action = ActionChains(self.browser)
        action.click_and_hold(slider).perform()
        # action.reset_actions()   # 清除之前的action
        for i in tracks:
            action.move_by_offset(xoffset=i, yoffset=0).perform()
        time.sleep(0.5)
        action.release().perform()

 

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读