def _pw_click(self, x, y): # Perform click in password input mode touch_actions = TouchActions(self.driver) touch_actions.tap_and_hold(x, y) touch_actions.release(x, y) touch_actions.perform() return 1
def act(self, x): x = int(x) if x == self.width: x -= 1 actions = TouchActions(self.browser) actions.tap_and_hold(x, 200) actions.move(x, 200).perform() time.sleep(1) actions.release(x, 200).perform()
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()
def _scroll(context, direction, percentage=50): """ :type context: HackedContext """ if isinstance(context.driver, iOSWebDriver): context.driver.swipe(direction, percentage) else: touch_action = TouchActions(context.driver).tap_and_hold(directions[direction][0][0], directions[direction][0][1]) touch_action.move(directions[direction][1][0], directions[direction][1][1]) touch_action.release(directions[direction][1][0], directions[direction][1][1]) touch_action.perform()
def step(self, x): actions = TouchActions(self.browser) actions.tap_and_hold(x, 200) actions.move(x, 200).perform() time.sleep(1) actions.release(x, 200).perform() time.sleep(3) score = self.browser.execute_script("return cc.js.getClassByName('GameManager').Instance.score;") done = False if score < self.last_score: print(score, self.last_score) done = True reward = score - self.last_score self.last_score = score return self.get_state(), reward, done
def inputpw(driver, pw): # get window size scr_width = driver.get_window_size()['width'] scr_height = driver.get_window_size()['height'] # define key sise key_width = 0.0785*scr_width # 0.0785 = key_width / scr_width key_height = 0.0679*scr_height # 0.0679 = key_height / scr_height gap_x_ratio = 0.0220 # gap_x_ratio = 25/src_width gap_y_ratio = 0.0165 # gap_y_ratio = 30/scr_height q_pos_x = 0.0074*scr_width q_pos_y = 0.6640*scr_height a_pos_x = 0.0574*scr_width z_pos_x = 0.1574*scr_width pos_map_x = {} pos_map_y = {} #line Q pos_map_x['q'] = q_pos_x + key_width/2 pos_map_y['q'] = q_pos_y + key_height/2 pos_map_x['w'] = q_pos_x + 1*key_width + 1*gap_x_ratio*scr_width + key_width/2 pos_map_y['w'] = q_pos_y + key_height/2 pos_map_x['e'] = q_pos_x + 2*key_width + 2*gap_x_ratio*scr_width + key_width/2 pos_map_y['e'] = q_pos_y + key_height/2 pos_map_x['r'] = q_pos_x + 3*key_width + 3*gap_x_ratio*scr_width + key_width/2 pos_map_y['r'] = q_pos_y + key_height/2 pos_map_x['t'] = q_pos_x + 4*key_width + 4*gap_x_ratio*scr_width + key_width/2 pos_map_y['t'] = q_pos_y + key_height/2 pos_map_x['y'] = q_pos_x + 5*key_width + 5*gap_x_ratio*scr_width + key_width/2 pos_map_y['y'] = q_pos_y + key_height/2 pos_map_x['u'] = q_pos_x + 6*key_width + 6*gap_x_ratio*scr_width + key_width/2 pos_map_y['u'] = q_pos_y + key_height/2 pos_map_x['i'] = q_pos_x + 7*key_width + 7*gap_x_ratio*scr_width + key_width/2 pos_map_y['e'] = q_pos_y + key_height/2 pos_map_x['o'] = q_pos_x + 8*key_width + 8*gap_x_ratio*scr_width + key_width/2 pos_map_y['o'] = q_pos_y + key_height/2 pos_map_x['p'] = q_pos_x + 9*key_width + 9*gap_x_ratio*scr_width + key_width/2 pos_map_y['p'] = q_pos_y + key_height/2 #line A pos_map_x['a'] = a_pos_x + key_width/2 pos_map_y['a'] = q_pos_y + gap_y_ratio*scr_height + key_height + key_height/2 pos_map_x['s'] = a_pos_x + 1*key_width + 1*gap_x_ratio*scr_width + key_width/2 pos_map_y['s'] = q_pos_y + gap_y_ratio*scr_height + key_height + key_height/2 pos_map_x['d'] = a_pos_x + 2*key_width + 2*gap_x_ratio*scr_width + key_width/2 pos_map_y['d'] = q_pos_y + gap_y_ratio*scr_height + key_height + key_height/2 pos_map_x['f'] = a_pos_x + 3*key_width + 3*gap_x_ratio*scr_width + key_width/2 pos_map_y['f'] = q_pos_y + gap_y_ratio*scr_height + key_height + key_height/2 pos_map_x['g'] = a_pos_x + 4*key_width + 4*gap_x_ratio*scr_width + key_width/2 pos_map_y['g'] = q_pos_y + gap_y_ratio*scr_height + key_height + key_height/2 pos_map_x['h'] = a_pos_x + 5*key_width + 5*gap_x_ratio*scr_width + key_width/2 pos_map_y['h'] = q_pos_y + gap_y_ratio*scr_height + key_height + key_height/2 pos_map_x['j'] = a_pos_x + 6*key_width + 6*gap_x_ratio*scr_width + key_width/2 pos_map_y['j'] = q_pos_y + gap_y_ratio*scr_height + key_height + key_height/2 pos_map_x['k'] = a_pos_x + 7*key_width + 7*gap_x_ratio*scr_width + key_width/2 pos_map_y['k'] = q_pos_y + gap_y_ratio*scr_height + key_height + key_height/2 pos_map_x['l'] = a_pos_x + 8*key_width + 8*gap_x_ratio*scr_width + key_width/2 pos_map_y['l'] = q_pos_y + gap_y_ratio*scr_height + key_height + key_height/2 #line Z pos_map_x['z'] = z_pos_x + key_width/2 pos_map_y['z'] = q_pos_y + 2*gap_y_ratio*scr_height + 2*key_height + key_height/2 pos_map_x['x'] = z_pos_x + 1*key_width + 1*gap_x_ratio*scr_width + key_width/2 pos_map_y['x'] = q_pos_y + 2*gap_y_ratio*scr_height + 2*key_height + key_height/2 pos_map_x['c'] = z_pos_x + 2*key_width + 2*gap_x_ratio*scr_width + key_width/2 pos_map_y['c'] = q_pos_y + 2*gap_y_ratio*scr_height + 2*key_height + key_height/2 pos_map_x['v'] = z_pos_x + 3*key_width + 3*gap_x_ratio*scr_width + key_width/2 pos_map_y['v'] = q_pos_y + 2*gap_y_ratio*scr_height + 2*key_height + key_height/2 pos_map_x['b'] = z_pos_x + 4*key_width + 4*gap_x_ratio*scr_width + key_width/2 pos_map_y['b'] = q_pos_y + 2*gap_y_ratio*scr_height + 2*key_height + key_height/2 pos_map_x['n'] = z_pos_x + 5*key_width + 5*gap_x_ratio*scr_width + key_width/2 pos_map_y['n'] = q_pos_y + 2*gap_y_ratio*scr_height + 2*key_height + key_height/2 pos_map_x['m'] = z_pos_x + 6*key_width + 6*gap_x_ratio*scr_width + key_width/2 pos_map_y['m'] = q_pos_y + 2*gap_y_ratio*scr_height + 2*key_height + key_height/2 #line digit: same as line A pos_map_x['1'] = q_pos_x + key_width/2 pos_map_y['1'] = q_pos_y + key_height/2 pos_map_x['2'] = q_pos_x + 1*key_width + 1*gap_x_ratio*scr_width + key_width/2 pos_map_y['2'] = q_pos_y + key_height/2 pos_map_x['3'] = q_pos_x + 2*key_width + 2*gap_x_ratio*scr_width + key_width/2 pos_map_y['3'] = q_pos_y + key_height/2 pos_map_x['4'] = q_pos_x + 3*key_width + 3*gap_x_ratio*scr_width + key_width/2 pos_map_y['4'] = q_pos_y + key_height/2 pos_map_x['5'] = q_pos_x + 4*key_width + 4*gap_x_ratio*scr_width + key_width/2 pos_map_y['5'] = q_pos_y + key_height/2 pos_map_x['6'] = q_pos_x + 5*key_width + 5*gap_x_ratio*scr_width + key_width/2 pos_map_y['6'] = q_pos_y + key_height/2 pos_map_x['7'] = q_pos_x + 6*key_width + 6*gap_x_ratio*scr_width + key_width/2 pos_map_y['7'] = q_pos_y + key_height/2 pos_map_x['8'] = q_pos_x + 7*key_width + 7*gap_x_ratio*scr_width + key_width/2 pos_map_y['8'] = q_pos_y + key_height/2 pos_map_x['9'] = q_pos_x + 8*key_width + 8*gap_x_ratio*scr_width + key_width/2 pos_map_y['9'] = q_pos_y + key_height/2 pos_map_x['0'] = q_pos_x + 9*key_width + 9*gap_x_ratio*scr_width + key_width/2 pos_map_y['0'] = q_pos_y + key_height/2 pos_map_x['upper'] = pos_map_x['q'] pos_map_y['upper'] = pos_map_y['z'] pos_map_x['digit'] = pos_map_x['q'] pos_map_y['digit'] = q_pos_y + 3*gap_y_ratio*scr_height + 3*key_height + key_height/2 pos_map_x['ok'] = pos_map_x['m'] pos_map_y['ok'] = pos_map_y['digit'] pwmode = 'lower' ''' pages = driver.find_element_by_xpath("//Button[@id='btnMainWallet']") touch_actions = TouchActions(driver) touch_actions.flick_element(pages,0,-100,0).perform() print "flick ok!!!!!!!!!!!!!" ''' for letter in pw: if letter >= 'a' and letter <= 'z': if pwmode !='lower': touch_actions = TouchActions(driver) touch_actions.tap_and_hold(pos_map_x['upper'],pos_map_y['upper']) touch_actions.release(pos_map_x['upper'],pos_map_y['upper']) touch_actions.perform() pwmode = 'lower' touch_actions = TouchActions(driver) touch_actions.tap_and_hold(pos_map_x[letter],pos_map_y[letter]) touch_actions.release(pos_map_x[letter],pos_map_y[letter]) touch_actions.perform() elif letter >= 'A' and letter <= 'Z': if pwmode !='upper': touch_actions = TouchActions(driver) touch_actions.tap_and_hold(pos_map_x['upper'],pos_map_y['upper']) touch_actions.release(pos_map_x['upper'],pos_map_y['upper']) touch_actions.perform() pwmode = 'upper' letter = chr(ord(letter) + 32) touch_actions = TouchActions(driver) touch_actions.tap_and_hold(pos_map_x[letter],pos_map_y[letter]) touch_actions.release(pos_map_x[letter],pos_map_y[letter]) touch_actions.perform() elif letter >= '0' and letter <= '9': if pwmode !='digit': touch_actions = TouchActions(driver) touch_actions.tap_and_hold(pos_map_x['digit'],pos_map_y['digit']) touch_actions.release(pos_map_x['digit'],pos_map_y['digit']) touch_actions.perform() pwmode = 'digit' touch_actions = TouchActions(driver) touch_actions.tap_and_hold(pos_map_x[letter],pos_map_y[letter]) touch_actions.release(pos_map_x[letter],pos_map_y[letter]) touch_actions.perform() else: print "unsupport sign now!" return 0 touch_actions = TouchActions(driver) touch_actions.tap_and_hold(pos_map_x['ok'],pos_map_y['ok']) touch_actions.release(pos_map_x['ok'],pos_map_y['ok']) touch_actions.perform() return 1
def act(self, x): actions = TouchActions(self.browser) actions.tap_and_hold(x, 200) actions.move(x, 200).perform() time.sleep(1) actions.release(x, 200).perform()
def drag_and_drop(self, source, target, parent=None, analysis=None): if analysis: analysis('start') touch = TouchActions(self) _source_coord = ast.literal_eval( source.get_attribute('ClickablePoint')) if not parent: _target_coord = ast.literal_eval( target.get_attribute('ClickablePoint')) logger.info('Source {0} Target {1}'.format(_source_coord, _target_coord), also_console=PolarisInterface.output_console) self.click(source) touch.tap_and_hold(_source_coord[0], _source_coord[1]) sleep(1) touch.release(_target_coord[0], _target_coord[1]).perform() if analysis: for i in range(1, 6): if not analysis('stop'): touch.perform() else: logger.warn( "Trouble interacting with {0}. Required {1} additional clicks to activate" .format(target.get_attribute('AutomationId'), i)) return logger.info('Unable to validate click after 10 tries') _target_box = self.get_boundingrect(target) _parent_box = self.get_boundingrect(parent) # Find overlap between boxes _overlap_box = list() # Check left and top coordinates _overlap_box.append(_target_box[0] if _target_box[0] > _parent_box[0] else _parent_box[0]) _overlap_box.append(_target_box[1] if _target_box[1] > _parent_box[1] else _parent_box[1]) # Check width and height _overlap_box.append(_target_box[2] if _overlap_box[0] + _target_box[2] < _overlap_box[0] + _parent_box[2] else _parent_box[0] + _parent_box[2] - _overlap_box[0]) _overlap_box.append(_target_box[3] if _overlap_box[1] + _target_box[3] < _overlap_box[1] + _parent_box[3] else _parent_box[1] + _parent_box[3] - _overlap_box[1]) x = random.randint(_overlap_box[0], _overlap_box[0] + _overlap_box[2]) y = random.randint(_overlap_box[1], _overlap_box[1] + _overlap_box[3]) self.click(source) touch.tap_and_hold(_source_coord[0], _source_coord[1]) sleep(1) touch.release(x, y).perform() if analysis: for i in range(1, 10): if not analysis('stop'): touch.perform() else: logger.warn( "Trouble interacting with {0}. Required {1} additional clicks to activate" .format(target.get_attribute('AutomationId'), i)) return raise AssertionError('Unable to validate click after 10 tries')