python - 无法点击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
解决方案
我查看了 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()
推荐阅读
- ubuntu - openvpn - 验证/解密数据包错误:数据包 HMAC 验证失败
- javascript - JQuery 文件输入 - 读取图像宽度和高度
- sql - SQL Server CHARINDEX 函数
- android-studio - Android Studio 调试器在到达断点后崩溃
- java - 如何通过 SSL 从开发机器连接到 Heroku shield Postgres 数据库
- azure - 使用 SignalR 的 Azure 应用服务访问限制
- snmp - 如何使用 snmp 修复未定义的标识符错误
- vue.js - Vue awesome swiper 在 vue js modal 插件中无法正常工作
- python-3.x - 如何抑制“类型没有预期的属性”
- javascript - 即使指定了宽度和高度,溢出 x 也不起作用