簡體   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