首页 > 解决方案 > 无法点击appium中的按钮,但其他一些还可以

问题描述

我是python新手,在编写测试用例时遇到问题。

实际上我尝试在 Appium 中使用 find_element 和 xpath 但它报告超时,然后我使用坐标方法并尝试单击按钮但仍然失败。奇怪的是我的一些按钮可以点击。

下面是我的代码:

    self.action2 = TouchAction(self.driver)

    i = 0
    while i < 10:
            self.driver.swipe(x / 2, y * 9/10, x / 2, y * 5/100)
            time.sleep(1)
            i += 1

    self.action2.move_to(700,2620).tap().perform()

我希望光标应该移动到(x 偏移,y 偏移)但它失败了。

这是日志:

>       self.user_login(username, password)
>       self.action2.move_to(700,2620).tap().perform()
C:\learnPython\lib\site-packages\appium\webdriver\common\touch_action.py:115: in move_to

>       self._add_action('moveTo', self._get_opts(el, x, y))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <appium.webdriver.common.touch_action.TouchAction object at 0x00000241EC651358>
element = 700, x = 2620, y = None, duration = None, pressure = None

>     def _get_opts(self, element, x, y, duration=None, pressure=None):
        opts = {}
        if element is not None:
>           opts['element'] = element.id
E           AttributeError: 'int' object has no attribute 'id'

C:\learnPython\lib\site-packages\appium\webdriver\common\touch_action.py:160: AttributeError

标签: pythonappium

解决方案


我查看了 appium 的源代码,我可以看到move_to得到 3 个参数https://github.com/appium/python-client/blob/master/appium/webdriver/common/touch_action.py#L104

因此,在您的情况下,您将element参数设置为 700,这就是出现错误的原因。

You can try either

self.action2.move_to(x=700,y=2620).tap().perform()

or

self.action2.move_to(None,700,2620).tap().perform()

推荐阅读