无法点击appium中的按钮,但其他一些没问题
can't click the button in appium but some others is okay
我是新手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,这就是出现错误的原因。
你可以试试
self.action2.move_to(x=700,y=2620).tap().perform()
或
self.action2.move_to(None,700,2620).tap().perform()
通过坐标定位元素不是继续进行的最佳方法,您将无法 运行 在具有其他屏幕分辨率、方向、密度等的设备上进行相同的测试。
所以我建议考虑替代方法,例如:
- 确保使用Explicit Wait以确保元素存在
- 确保使用正确的
automationName
能力
- 如果元素在 WebView - consider switching the context to the webview
中
我是新手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,这就是出现错误的原因。
你可以试试
self.action2.move_to(x=700,y=2620).tap().perform()
或
self.action2.move_to(None,700,2620).tap().perform()
通过坐标定位元素不是继续进行的最佳方法,您将无法 运行 在具有其他屏幕分辨率、方向、密度等的设备上进行相同的测试。
所以我建议考虑替代方法,例如:
- 确保使用Explicit Wait以确保元素存在
- 确保使用正确的
automationName
能力 - 如果元素在 WebView - consider switching the context to the webview 中