还未发布过话题
  • 报道~

  • def tap_el(self, element, times: int):
        """
        单击某个控件N次
        :param element: 要单击的控件
        :param times: 要单击的次数
        :return:
        """
        def _center_rect(r):
            # center_x = r['x'] + r['width'] / 2.0
            # center_y = r['y'] + r['height'] / 2.0
            center_x = r['width'] / 2.0
            center_y = r['height'] / 2.0
            return center_x, center_y
    
        rect = element.rect
        # HTNone 的设计缺陷导致不能准确的识别有效元素
        # 后期可能去掉HTNone
        if isinstance(rect, bool):
            return
    
        action = TouchAction(self)
        center = _center_rect(element.rect)
        action.tap(element=element,
                   x=center[0],
                   y=center[1],
                   count=times).perform()
    
  • iOS 目前是没有问题的,但是 Android 还有问题

    def tap_el(self, element, times: int):
        """
        单击某个控件N次
        :param element: 要单击的控件
        :param times: 要单击的次数
        :return:
        """
        def _center_rect(r):
            # center_x = r['x'] + r['width'] / 2.0
            # center_y = r['y'] + r['height'] / 2.0
            center_x = r['width'] / 2.0
            center_y = r['height'] / 2.0
            return center_x, center_y
    
        rect = element.rect
        # HTNone 的设计缺陷导致不能准确的识别有效元素
        # 后期可能去掉HTNone
        if isinstance(rect, bool):
            return
    
        action = TouchAction(self)
        center = _center_rect(element.rect)
        action.tap(element=element,
                   x=center[0],
                   y=center[1],
                   count=times).perform()
    
  • Appium 有现成的点击方案,(iOS 没有问题, Android 有问题)

    def tap_el(self, element, times: int):
        """
        单击某个控件N次
        :param element: 要单击的控件
        :param times: 要单击的次数
        :return:
        """
        def _center_rect(r):
            # center_x = r['x'] + r['width'] / 2.0
            # center_y = r['y'] + r['height'] / 2.0
            center_x = r['width'] / 2.0
            center_y = r['height'] / 2.0
            return center_x, center_y
    
        rect = element.rect
        # HTNone 的设计缺陷导致不能准确的识别有效元素
        # 后期可能去掉HTNone
        if isinstance(rect, bool):
            return
    
        action = TouchAction(self)
        center = _center_rect(element.rect)
        action.tap(element=element,
                   x=center[0],
                   y=center[1],
                   count=times).perform()
    
  • 单纯的过来点个赞

  • def long_press(self, element, duration):
    def center_rect(r):
    center_x = r['x'] + r['width'] / 2.0
    center_y = r['y'] + r['height'] / 2.0
    return center_x, center_y

    duration = duration * 10000
    center = center_rect(element.rect)
    self.driver.tap([center], duration=duration)

    尝试了以上所有的方法, 发现一个本质的错误, 点击位置在元素的左上角,所以导致长按等操作无法触发。
    将其改为中心后,问题解决

  • 身在百度 at 2019年05月06日

    还在百度吗? 约个饭啊