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()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章