Пример #1
0
 def drag_check(self):
     """
     拖动模块
     如果发布拖动不流畅,请修改
     修改 selenium 源码 /selenium/webdriver/common/actions/pointer_input.py 文件中的 DEFAULT_MOVE_DURATION = 250 的值,到50左右,
     :return:
     """
     title = self.brower.title
     if title == '认证魔方':
         self.lg.info("{},等待60秒".format(title))
         time.sleep(60)
     gap = self.get_img_gap()
     self.lg.info("gap:%s" % gap)
     drag_div = r'//div/div[@class="JDJRV-smallimg"]/img'
     element = self.brower.find_element_by_xpath(drag_div)
     action_chains = ActionChains(self.brower)
     action_chains.click_and_hold(on_element=element)
     action_chains.pause(0.2)
     offsets, tracks = easing.get_tracks(gap, 4, 'ease_out_expo')
     # tracks = self.get_track(gap)
     self.lg.info("tracks:", len(tracks), tracks)
     for track in tracks:
         action_chains.move_by_offset(track, 0)
     action_chains.pause(random.uniform(0.5, 0.9))
     action_chains.release()
     action_chains.perform()
     time.sleep(random.randint(3, 9))
Пример #2
0
    def verify_action(self):
        try:
            iLoginCounDown = self.driver.find_element_by_xpath(
                '//*[@id="iLoginCounDown"]')
            time.sleep(1)
            r = requests.post('http://z-sms.com/admin/smslist.php', data = {'PhoNum':self.phone})
            sms = r.json()

            print(sms)
        except NoSuchElementException:
            print("No element found")

            sendCodeBtn = self.driver.find_element_by_xpath(
                '//*[@id="sendCodeBtn"]')
            sendCodeBtn.click()
            time.sleep(3)
            try:
                yodaBox = self.driver.find_element_by_xpath('//*[@id="yodaBox"]')
            except NoSuchElementException:
                self.verify_action()
            touch = TouchActions(self.driver)
            r = random.randint(1,2)
            if r == 1:
                tracks = self.get_track(270)
            else:
                offsets, tracks = easing.get_tracks(265, 10, 'easeInOutQuint')
                
            print(tracks)
            # offsets, tracks = easing.get_tracks(265, 10, 'easeInOutQuint')
            # print(tracks)
            # print(offsets)
            loc = yodaBox.location
            x = loc['x']+10
            y1 = loc['y']+10
            y2 = y1 +3
            y3 = y1 +6
            touch.tap_and_hold(x, y1)
            y_d = []
            # for track in track_list:
            #     x += track
            #     tmp = y + random.randint(-2,3) 
            #     touch.move(x+track, tmp)
            for i,track in enumerate(tracks):
                x += track
                if i/len(tracks) < 1/5 or i/len(tracks) > 4/5:
                    y = y1
                elif 2/5 <= i/len(tracks) <= 3/5:
                    y = y3
                else:
                    y = y2 
                y_d.append(y)
                touch.move(x, y)
            touch.release(x, y).perform()
            print(y_d)
            self.verify_action()
Пример #3
0
def fake_drag(browser, knob, offset):
    '''
    模拟人性的滑动行为(防止被识别为机器行为)
    :param browser: 游览器对象
    :param knob: 移动滑块对象
    :param offset: 移动滑块移动的距离
    :return:
    '''
    offsets, tracks = easing.get_tracks(
        offset, 20, 'ease_out_expo'
    )  # 获取一种人性行为的滑动规则(总体参试一下几种滑动规则,还是ease_out_expo()该方法正确度比较高)
    print 'offsets:', offsets
    print 'tracks:', tracks  # tracks是运动轨迹列表
    ActionChains(browser).click_and_hold(knob).perform()
    for x in tracks:
        ActionChains(browser).move_by_offset(x, 0).perform()
    # ActionChains(browser).pause(0.5).release().perform()
    ActionChains(browser).release().perform()
Пример #4
0
def fake_drag(browser, knob, offset):
    # seconds = random.uniform(2, 6)
    # print(seconds)
    # samples = int(seconds*10)
    # diffs = sorted(random.sample(range(0, offset), samples-1))
    # diffs.insert(0, 0)
    # diffs.append(offset)
    # ActionChains(browser).click_and_hold(knob).perform()
    # for i in range(samples):
    #     ActionChains(browser).pause(seconds/samples).move_by_offset(diffs[i+1]-diffs[i], 0).perform()
    # ActionChains(browser).release().perform()

    # tracks = get_track(offset)
    offsets, tracks = easing.get_tracks(offset, 12, 'ease_out_expo')
    print(offsets)
    ActionChains(browser).click_and_hold(knob).perform()
    for x in tracks:
        ActionChains(browser).move_by_offset(x, 0).perform()
    ActionChains(browser).pause(0.5).release().perform()

    return
Пример #5
0
def fake_drag(browser, knob, offset):
    offsets, tracks = easing.get_tracks(offset, 1, 'ease_out_expo')
    ActionChains(browser).click_and_hold(knob).perform()
    for x in tracks:
        ActionChains(browser).move_by_offset(x, 0).perform()
    ActionChains(browser).pause(0.2).release().perform()