繁体   English   中英

不能单击appium中的按钮,但其他一些是可以的

[英]can't click the button in appium but some others is okay

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

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

以下是我的代码:

    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:NameError

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

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

你也可以试试

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

要么

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

通过坐标定位元素不是最好的方法,您将无法在具有其他屏幕分辨率,方向,密度等的设备上运行相同的测试。

所以我建议考虑以下替代方法:

  1. 确保使用显式等待以确保元素存在
  2. 确保使用正确的automationName功能
  3. 如果元素在WebView中 - 考虑将上下文切换到webview

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM