Exemplo n.º 1
1
 def __login_process(self):
     driver = self.driver
     driver.get(game_url)
     self.__wait(2)
     start_btn = driver.find_element_by_id("sp_sc_5")
     TouchActions(driver).tap(start_btn).perform()
     self.__wait(3)
     try:
         login_comfirm = driver.find_element_by_id("sp_sc_5")
         TouchActions(driver).tap(login_comfirm).perform()
         self.__wait(2)
     except:
         pass
     while self.__check_notice():
         self.__wait(2)
     while True:
         if not self.__check_scene('の里'):
             if not self.__check_notice():
                 driver.get(home_url)
                 self.__wait(2)
             else:
                 self.__wait(2)
         else:
             break
     self.__write_log("login")
Exemplo n.º 2
1
def dbl_click_item(id=id, save_screenshot=False, save_screenshot_file=None, max_retry=3):
    _wait_for_id(id=id, save_screenshot=save_screenshot,
                 save_screenshot_file=save_screenshot_file)
    element = driver.find_element_by_id(id)

  

    if platform == 'android':
        actions = TouchActions(driver)
        actions.double_tap(element)

    retry_count = 1
    while retry_count <= max_retry:
        try:
            if platform == 'ios':
                # Fix TBD
                log ('Hacky iOS double tap to a fixed location')
                driver.execute_script('mobile: doubleTap', {'x':200, 'y':200})
            else:
                actions.perform()
        except Exception as e:
            log('action error, try #{}...'.format(retry_count))
            log ('Error reported was: '+str(e))
            retry_count = retry_count + 1
            sleep(2)
        else:
            retry_count = max_retry + 1
            pass
Exemplo n.º 3
0
 def login(self, url):
     # cookies = browser.get_cookies(url=self.login_url, signbot=self.bot)
     # self.session.cookies.update(cookies)
     self.session._driver = None
     if self.is_mobile:
         self.session.webdriver_options.add_experimental_option("mobileEmulation", mobile_emulation)
         driver = self.session.driver
         # 模拟触控操作
         # https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.touch_actions.html
         tap_loginbtn = TouchActions(driver)
         driver.get(url)
         user_input = driver.find_element_by_id('username')
         password_input = driver.find_element_by_id('password')
         login_btn = driver.find_element_by_id('loginBtn')
         user_input.send_keys(self.bot.user.username)
         password_input.send_keys(self.bot.user.password)
         tap_loginbtn.tap(login_btn).perform()
         time.sleep(6)
         nickname = driver.find_element_by_css_selector('#myHeader span[class$="name_text"]')
         nickname = nickname.text
         self.logger.info('登陆成功,欢迎{}'.format(nickname))
         print('登陆成功')
     else:
         self.login_pc(url)
     self.session.transfer_driver_cookies_to_session()
     self.session.driver.close()
Exemplo n.º 4
0
 def __change_food(self):
     driver = self.driver
     if not self.__check_scene('の里'):
         return False
     firetext = driver.find_element_by_xpath("//span[@id='element_fire']")
     if int(firetext.text) <= 0:
         return False
     try:
         a = driver.find_element_by_xpath("//area[contains(@title,'楽市楽座')]")
         TouchActions(driver).tap(a).perform()
         sleep(1)
         a = driver.find_element_by_xpath(
             "//img[contains(@src,'btn_trade_all')]/..")
         TouchActions(driver).tap(a).perform()
         sleep(1)
         btns = driver.find_elements_by_id("neko-alert-dynamic-ok-button")
         for btn in btns:
             if btn.is_displayed():
                 TouchActions(driver).tap(btn).perform()
                 break
         self.__wait(2)
         driver.refresh()
         self.__wait(2)
     except:
         return False
     return True
Exemplo n.º 5
0
 def swipe_left(self, duration=1):
     WebDriverWait(self, 10).until(
         ExpectedConditions.presence_of_element_located(
             (By.ID, self.get_element_id("drag_area"))))
     pager = self.find_element_by_id('drag_area')
     flick = TouchActions(self).flick_element(pager, -1000, 0, 70)
     flick.perform()
    def test_Level(self):  # 测试用例必须以test开头
        freeSalePage_url = url3
        driver = get_url(freeSalePage_url)
        page = StudyPlan(driver)
        chooseStudyInfo(page)
        # driver.TouchActions.scroll("am-picker-col-mask", 0, +200).perform()
        element1 = page.am_picker_col_indicator_loc()[0]
        TouchActions(driver).long_press(element1)
        TouchActions(driver).flick_element(element1, 0, 300, 30).perform()

        time.sleep(3)
        page.study_plan_bt_btn_loc()[0].click()  # 选择完年龄点击完成水平测试
        time.sleep(5)
        page.imager_inner_loc()[2].click()  # 点击定制专属学习计划
        time.sleep(5)
        page.select_item_loc()[2].click()  # 选择期望提升
        time.sleep(5)

        get_sale_page(page)

        startingLevel = page.study_target_item_content_loc()[0].get_attribute(
            'innerHTML')
        targetingLevel = page.study_target_item_content_loc()[1].get_attribute(
            'innerHTML')
        self.assertEqual(startingLevel, u'Lv.3', msg='失败')  # 验证起始等级为lv3
        self.assertEqual(targetingLevel, u'Lv.5', msg='失败')  # 验证目标等级为lv5
def get_post(target_url):
    while 1:
        try:
            option.add_argument(f"--proxy-server={random.choice([i['ip'] for i in client.ips.ips.find()])}")
            break
        except:time.sleep(0.5)
    option.add_argument(random.choice(user_agent_list))
    option.add_experimental_option('w3c', False)
    driver = webdriver.Chrome(chrome_options=option)
    # driver.maximize_window()
    try:
        driver.get(target_url)
        print(target_url)
        ui.WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, '//a[@class="block"]')))
    except TimeoutException as e:
        driver.quit()
        print(e)
        return
    button = driver.find_element_by_xpath('//a[@class="block"]')
    Action = TouchActions(driver)
    Action.scroll_from_element(button, 0, 5000).perform()
    datas = driver.find_elements_by_tag_name('a')
    urls = [i for i in [i.get_attribute('href') for i in datas if i.get_attribute('href')] if 'detail' in i]
    for url in urls:
        try:
            client.all_post.mogujie_detail_url.insert({'_id': url, 'status': 0})
            print('over:', url)
        except Exception as e:
            print(e)
    client.all_post.mogujie_user.update({'_id': target_url}, {'$set': {'status': 1}})
    driver.quit()
Exemplo n.º 8
0
	def page_flick(self, start_locator, end_locator):

		driver = self._current_application()
		el1 = self._element_find(start_locator, True, True)
		el2 = self._element_find(end_locator, True, True)
		action = TouchActions(driver)
		action.long_press(el1).move_to(el2).release().perform()
Exemplo n.º 9
0
 def find_text_touch(self, text="", down=0, right=0, xpath=None, find=""):
     """安住某个键滑动上下滑动
     xpath: 可传xath
     down 和right 其中一个不写默认0
     down:  down<0 往下滑动 , down>0 往上滑动
     right: right<0 往右面滑动 , right>0 往左滑动
     down 和right 是滑动的速度
     """
     if xpath:
         button = self.driver.find_element_by_xpath(xpath)
     else:
         button = self.driver.find_element_by_xpath(
             f'//android.widget.TextView[@text="{text}"]')
     Action = TouchActions(self.driver)
     for i in range(100, 2500, 100):
         print('移动大小为:', i)
         if right > 0:
             Action.flick_element(button, -i, 0, abs(right)).perform()
         elif right < 0:
             Action.flick_element(button, i, 0, abs(right)).perform()
         else:
             pass
         if down > 0:
             Action.flick_element(button, -i, 0, abs(down)).perform()
         elif down < 0:
             Action.flick_element(button, i, 0, abs(down)).perform()
         else:
             pass
         html = self.driver.page_source
         info = Selector(text=html)
         buttons = info.xpath('//@text').extract()
         buttons = [i for i in buttons if i != '']
         if find in buttons:
             time.sleep(1)
             break
Exemplo n.º 10
0
 def test_contexts_list(self):
     el = self.driver.find_element_by_class_name('android.widget.ListView')
     els = el.find_elements_by_class_name('android.widget.TextView')
     pdb.set_trace()
     ta = TouchActions(self.driver).flick_element(el, 0, -300, 0)
     ta.perform()
     sleep(5)
Exemplo n.º 11
0
def scut():
    browser.get(
        'https://member.dossen.com/member/login/phone?redirect_uri=https%253A%252F%252Fshop.m.dossen.com%252Fsignin%252Findex&salerCode='
    )
    # 将窗口最大化
    browser.maximize_window()
    time.sleep(1)
    browser.set_window_size(375, 812)
    # 格式是PEP8自动转的
    # 这里是找到输入框,发送要输入的用户名和密码,模拟登陆
    time.sleep(random.randint(1, 2))
    browser.find_element_by_xpath("//*[@id='userName']").send_keys(
        os.environ['SCUT_USER'])
    time.sleep(random.randint(1, 2))
    browser.find_element_by_xpath("//*[@id='password']").send_keys(
        os.environ['SCUT_PASSWORD'])
    # 在输入用户名和密码之后,点击登陆按钮
    time.sleep(random.randint(1, 3))
    browser.find_element_by_xpath("/html/body/div[1]/div[2]").click()
    time.sleep(random.randint(1, 2))
    huakuai = browser.find_element_by_xpath(
        '//*[@id="layui-m-layer0"]/div[2]/div/div/div/div/div/div/div/span[1]')
    tuodong = TouchActions(browser)
    tuodong.flick_element(huakuai, 420, 0, 2).perform()
    time.sleep(random.randint(2, 10))
    browser.find_element_by_xpath('//*[@id="app"]/div[3]/div/div[3]').click()
    chenggong = browser.find_element_by_xpath('//*[@id="app"]/div[1]/div')
    text = chenggong.text
    print(text)
    print('已签到了吧!')
Exemplo n.º 12
0
    def test_contexts_list(self):
        el = self.driver.find_element_by_class_name('android.widget.ListView')
        els = el.find_elements_by_class_name('android.widget.TextView')

        ta = TouchActions(self.driver).flick_element(el, 0, -300, 0)
        ta.perform()
        sleep(5)
def scroll_down(driver, y_value=None, times=None):
    """"Procedure to scroll down a web page for n times or
    scroll it till its end if <times> is undefined
    """

    if y_value:
        for _ in range(0, times):
            # scroll down the browser n times to load <comments number>
            TouchActions(driver).scroll(0, y_value).perform()
            time.sleep(SCROLL_PAUSE_TIME)

        return BeautifulSoup(driver.page_source, features='html5lib')

    else:
        # repeating scroll down the window until no more comments are loaded
        soup = BeautifulSoup(driver.page_source, features='html5lib')

        while True:
            all_videos = soup.find_all('a', id='video-title',
                                       class_='yt-simple-endpoint style-scope ytd-grid-video-renderer')
            TouchActions(driver).scroll(0, Y_SCROLL * 10).perform()
            time.sleep(SCROLL_PAUSE_TIME)
            soup = BeautifulSoup(driver.page_source, features='html5lib')
            new_videos = soup.find_all('a', id='video-title',
                                       class_='yt-simple-endpoint style-scope ytd-grid-video-renderer')

            if new_videos == all_videos:
                driver.close()
                return new_videos
    def select_timeslot(self, product):
        """
        click time slot[express delivery] and click ok for chicken
        or else select schedule quantity and cilck ok
        :param product: this variable to verify chicken or marinades

        """
        if product == "chicken":
            self.driver.implicitly_wait(19)
            self.driver.find_element_by_css_selector(self.CSS_SELECTDELIVERTTIME).click()
            time.sleep(5)
            try:
                self.driver.find_element_by_css_selector(self.CSS_EXPRESSDELIVERY).click()
            except:
                self.driver.find_element_by_css_selector(self.CSS_EXPRESSDELIVERY1).click()
            self.driver.find_element_by_css_selector(self.CSS_OK).click()
            time.sleep(7)
        elif product == "marinades":
            self.driver.implicitly_wait(19)
            torow = self.driver.find_element_by_css_selector(self.CSS_SCHEDULETOMORROW)
            action = TouchActions(self.driver)
            action.tap(torow).perform()
            time.sleep(2)
            self.driver.find_element_by_css_selector(self.CSS_SELECTDELIVERTTIME).click()
            try:
                time.sleep(2)
                self.driver.find_element_by_css_selector(self.CSS_SCHEDULEDELIVERY).click()
            except:
                self.driver.find_element_by_css_selector(self.CSS_SCHEDULEDELIVERY1).click()
            time.sleep(2)
            self.driver.find_element_by_css_selector(self.CSS_OK).click()
            time.sleep(7)
Exemplo n.º 15
0
    def page_flick(self, start_locator, end_locator):

        driver = self._current_application()
        el1 = self._element_find(start_locator, True, True)
        el2 = self._element_find(end_locator, True, True)
        action = TouchActions(driver)
        action.long_press(el1).move_to(el2).release().perform()
Exemplo n.º 16
0
 def async_loading(self):
     """上拉分页"""
     time.sleep(3)
     Action = TouchActions(self.driver)
     clickHoldElement = self.by_xpath_name(
         '//*[@id="191936765"]/div[1]/span')
     Action.scroll_from_element(clickHoldElement, 0, 2500).perform()
     time.sleep(3)
Exemplo n.º 17
0
 def manage_payment(self):
     """
     check manage payment and visiblity of card
     """
     payment = self.driver.find_element_by_css_selector(
         self.CSS_MANAGE_PAYMENTLINK)
     action = TouchActions(self.driver)
     action.tap(payment).perform()
    def scroll(self, x_offset, y_offset):
        """ Scrolls from current position.

         ``x_offset`` is the X offset to scroll to.

         ``y_offset`` is the Y offset to scroll to."""
        action = TouchActions(self._current_application())
        action.scroll(x_offset, y_offset).perform()
    def flick(self, x_speed, y_speed):
        """ Flicks from current position.

         ``x_speed`` is the X speed in pixels per second.

         ``y_speed`` is the Y speed in pixels per second."""
        action = TouchActions(self._current_application())
        action.flick(x_speed, y_speed).perform()
 def drag_and_drop_by_touch_offset(self, locator, x_offset=0, y_offset=0):
     """Drags the element found with ``locator `` to the given ``x_offset`` and ``y_offset``
     coordinates using touch actions."""
     source_element = self._element_find(locator, True, True)
     actions = TouchActions(self._current_application())
     source_x_center = source_element.location.get('x') + (source_element.size.get('width') / 2)
     source_y_center = source_element.location.get('y') + (source_element.size.get('height') / 2)
     actions.tap_and_hold(source_x_center, source_y_center).release(x_offset, y_offset).perform()
Exemplo n.º 21
0
 def down_refresh_data(self):
     """下拉刷新"""
     Action = TouchActions(self.driver)
     clickHoldElement = self.by_xpath_name(
         '//*[@id="191936765"]/div[1]/span')
     Action.scroll_from_element(clickHoldElement, 0,
                                -200).perform()  # 下拉刷新是负数
     time.sleep(3)
Exemplo n.º 22
0
 def outofstock_pop(self):
     """
     check out of stock popup
     """
     WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'button#close-button')))
     popup=self.driver.find_element_by_css_selector('button#close-button')
     action = TouchActions(self.driver)
     action.tap(popup).perform()
Exemplo n.º 23
0
def get_user():
    driver = webdriver.Chrome(chrome_options=option)
    driver.get('https://www.mogu.com/')
    # ui.WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, '//div[@class="column-wrap"]')))
    time.sleep(5)
    button = driver.find_element_by_xpath('//a')
    Action = TouchActions(driver)
    Action.scroll_from_element(button, 0, 10000).perform()
    def get_comment_info_list(self):
        shop_collcetion = Mongodb(db=TravelDriver.db,
                                  collection=TravelDriver.shop_collection,
                                  host='localhost').get_collection()
        shop_name_url_list = list()
        for i in shop_collcetion.find(self.get_data_key()):
            if i.get('shop_comment_url'):
                shop_name_url_list.append(
                    (i.get('shop_name'), i.get('shop_comment_url')))

        for i in range(len(shop_name_url_list)):
            # 可能会有反爬
            self.info_log(data='第%s个,%s' % (i + 1, shop_name_url_list[i][0]))
            self.shop_name = shop_name_url_list[i][0]
            self.fast_new_page(url=shop_name_url_list[i][1])
            time.sleep(5)

            # main-page > header > h2 > div:nth-child(2)
            try:
                #查看是否有顶部按钮 有就点击
                dianping = self.driver.find_element_by_css_selector(
                    css_selector='#main-page > header > h2 > div:nth-child(2)')
                self.fast_click_same_page_by_css_selector(
                    click_css_selector=
                    '#main-page > header > h2 > div:nth-child(2)')

                time.sleep(6)
            except Exception as e:
                print(111)
            #点击最新的
            try:
                new = self.driver.find_element_by_xpath(
                    '//li[@data-tagtype="44"]')
                ActionChains(self.driver).click(new).perform()

                time.sleep(5)
            except Exception as e:
                print(222)

            #向下进行滚动
            try:
                button = self.driver.find_element_by_css_selector(
                    css_selector=
                    '#main-page > div.mp-comment-mpcon > div.mp-addcomment.mp-border-top > a > div'
                )

                Action = TouchActions(self.driver)
                Action.scroll_from_element(on_element=button,
                                           xoffset=0,
                                           yoffset=int(8000)).perform()
                time.sleep(5)
            except Exception as e:
                print(333)
            self.fast_click_same_page_by_css_selector(
                click_css_selector='#main-page > div.mp-gotop > div')
            time.sleep(6)
            comment_data_list = self.from_page_get_data_list(
                page=page_comment_1)
Exemplo n.º 25
0
 def test_touchaction(self):
     self.driver.get("https://www.baidu.com")
     touchaction = TouchActions(self.driver)
     el = self.driver.find_element_by_id("kw")
     el_search = self.driver.find_element_by_id("su")
     el.send_keys('健身')
     el_search.click()
     touchaction.scroll_from_element(el, 0, 10000).perform()
     time.sleep(5)
Exemplo n.º 26
0
 def click_managingaddress(self):
     """
     click managing address option
     """
     m = self.driver.find_element_by_css_selector(self.CSS_MANAGINGADDRESS)
     action = TouchActions(self.driver)
     action.tap(m).perform()
     time.sleep(2)
     self.driver.implicitly_wait(5)
    def scroll_from_element(self, locator, x_offset, y_offset):
        """ Scrolls starting from ``locator``.

         ``x_offset`` is the X offset to scroll to.

         ``y_offset`` is the Y offset to scroll to."""
        element = self._element_find(locator, True, True)
        action = TouchActions(self._current_application())
        action.scroll_from_element(element, x_offset, y_offset).perform()
Exemplo n.º 28
0
    def send_otp(self):
        """
        login via otp

        """
        time.sleep(0.5)
        otp = self.driver.find_element_by_css_selector(self.CSS_SENTOTP)
        action = TouchActions(self.driver)
        action.tap(otp).perform()
Exemplo n.º 29
0
    def click_search(self):
        """
        click serach button

        """
        time.sleep(5)
        Search = self.driver.find_element_by_css_selector(self.CSS_SEARCH)
        action = TouchActions(self.driver)
        action.tap(Search).perform()
Exemplo n.º 30
0
 def click_managingprofile(self):
     """
     click managing profile option
     """
     m = self.driver.find_element_by_css_selector(self.CSS_MANAGINGPROFILE)
     action = TouchActions(self.driver)
     action.tap(m).perform()
     time.sleep(2)
     self.driver.implicitly_wait(5)
Exemplo n.º 31
0
 def click_proceed_search(self):
     time.sleep(0.3)
     proceedbutton = self.driver.find_element_by_css_selector(
         self.CSS_PROCEED)
     action = TouchActions(self.driver)
     action.tap(proceedbutton).perform()
     WebDriverWait(self.driver, 10).until(
         EC.invisibility_of_element_located(
             (By.CSS_SELECTOR, self.CSS_LOADER)))
Exemplo n.º 32
0
 def click_addnewaddress(self):
     """
     click add new address  button
     """
     AddAddress = self.driver.find_element_by_css_selector(
         self.CSS_ADDNEWADDRESS)
     action = TouchActions(self.driver)
     action.tap(AddAddress).perform()
     time.sleep(2)
Exemplo n.º 33
0
    def done(self):

        time.sleep(5)
        WebDriverWait(self.driver, 25).until(
            EC.visibility_of_element_located((By.CSS_SELECTOR, self.CSS_DONE)))

        donebutton = self.driver.find_element_by_css_selector(self.CSS_DONE)
        action = TouchActions(self.driver)
        action.tap(donebutton).perform()
Exemplo n.º 34
0
 def test_slider(self):
     # go to controls
     self._open_menu_position(1)
     # get the slider
     slider = self.driver.find_element_by_tag_name("slider")
     self.assertEqual(slider.get_attribute("value"), "50%")
     drag = TouchActions(self.driver)
     drag.flick_element(slider, -0.5, 0, 0)
     drag.perform()
     self.assertEqual(slider.get_attribute("value"), "0%")
class GoogleSearch_Page():

    def __init__(self,driver):
      self.driver=driver
      self.touchAction = TouchActions(driver)
             
    def enterSearchKeyword(self, str):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchField')
        self.driver.find_element_by_id(locator).clear()
        self.driver.find_element_by_id(locator).send_keys(str)
        
                                     
    def clickOnSearchButton(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchButton')
        self.driver.find_element_by_name(locator).click()

    def asertTextField(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchField')
        self.assertTrue(self.is_element_present(self.ByLocator(locator)))

    def assertButton(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchButton')
        self.assertTrue(self.is_element_present(By.XPATH, locator))

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True

    def tapOnTextField(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchField')
        element = self.driver.find_element_by_id(locator)
        self.touchAction.tap(element).perform()

    def tapOnSearchButton(self):
        reader = ReaderFile.ReadXML()
        locator = reader.readXml('SearchButton')
        element = self.driver.find_element_by_name(locator)
        self.touchAction.tap(element).perform()

        
    

    def waitTillElementPresent(self,id):
        for i in range(60):
            try:
                if self.is_element_present(By.ID, id): break
            except: pass
            time.sleep(1)
        else: print("unable to find element "+id+" in time")            
Exemplo n.º 36
0
    def swipe_screen_down(cls, element_id, x=0, y=-500, speed=0):
        """
        发送触摸手势给设备 flick(轻触)
        引导页滑动
        """
        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())

        pages = env.driver.find_element_by_id(element_id)
        touch_actions = TouchActions(env.driver)
        touch_actions.flick_element(pages, x, y, speed).perform()
Exemplo n.º 37
0
 def test_scroll(self):
     # scroll menu
     # get initial third row location
     row = self.driver.find_elements_by_tag_name("tableCell")[2]
     location1 = row.location
     # perform swipe gesture
     swipe = TouchActions(self.driver).flick(0, -20)
     swipe.perform()
     # get new row coordinates
     location2 = row.location
     self.assertEqual(location1['x'], location2['x'])
     self.assertNotEqual(location1['y'], location2['y'])
Exemplo n.º 38
0
    def Tap_App(cls):
        log.step_normal("Element [%s]: Do Tap_App()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        element = env.driver.find_elements(cls.by, cls.value)

        actions = TouchActions(env.driver)
        actions.tap(element)
        actions.perform()

        time.sleep(3)
        cls.__clearup()
Exemplo n.º 39
0
    def LongClickList_App(cls):
        log.step_normal("Element [%s]: Do LongClickList_App()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_elements(cls.by, cls.value)
        rd = random.randint(0, len(elements)-1)

        actions = TouchActions(env.driver)
        actions.long_press(elements[rd])
        actions.perform()

        time.sleep(3)
        cls.__clearup()
Exemplo n.º 40
0
Arquivo: o2oA.py Projeto: chaonin/aaba
 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
Exemplo n.º 41
0
 def swipe(self, points):
     automationName = self.driver.capabilities.get('automationName')
     last_x = 0
     last_y = 0
     if (automationName == 'Appium'):
         action_appium = TouchAction(self.driver)
         for i in range(0, len(points)):
             x = float(points[i][0]) * self.ratioX
             y = float(points[i][1]) * self.ratioY
             if (i == 0):
                 action_appium = action_appium.press(None, x, y).wait(200)
             elif (i == (len(points) - 1)):
                 action_appium = action_appium.move_to(None, x - last_x, y - last_y).wait(200).release()
                 action_appium.perform()
             else:
                 action_appium = action_appium.move_to(None, x - last_x, y - last_y).wait(200)
             last_x = x
             last_y = y
     else:
         action_selendroid = TouchActions(self.driver)
         for i in range(0, len(points)):
             x = float(points[i][0]) * self.ratioX
             y = float(points[i][1]) * self.ratioY
             if (i == 0):
                 action_selendroid.tap_and_hold(x, y)
             elif (i == (len(points) - 1)):
                 action_selendroid.move(x, y).release(x, y).perform()
             else:
                 action_selendroid.move(x, y)
Exemplo n.º 42
0
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()
Exemplo n.º 43
0
def swipe_left(duration=1):
    WebDriverWait(driver, 10).until(
        ExpectedConditions.presence_of_element_located((By.ID, get_element_id("drag_area"))))
    pager = find_element_by_id('drag_area');
    flick = TouchActions(driver).flick_element(pager, -1000, 0, 70);
    flick.perform();
 def __init__(self,driver):
   self.driver=driver
   self.touchAction = TouchActions(driver)
Exemplo n.º 45
0
def swipe_screen_down(driver,element_id,x=0,y=-300,speed=0):
	from selenium import webdriver
	from selenium.webdriver.common.touch_actions import TouchActions
	pages = driver.find_element_by_id(element_id)
	touch_actions = TouchActions(driver)              
	touch_actions.flick_element(pages,x,y,speed).perform()
Exemplo n.º 46
0
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 long_press(self, tag_name, id_or_name):
     """ Long press the element """
     driver = self._current_application()
     element = self._find_element_by_tag_name(tag_name, id_or_name)
     long_press = TouchActions(driver).long_press(element)
     long_press.perform()