【问题标题】:How to tap by coordinates using appium in python如何在python中使用appium通过坐标点击
【发布时间】:2020-05-06 14:04:12
【问题描述】:

我在 python 中尝试使用 appium 按坐标点击时遇到此错误:

AttributeError: 'list' 对象没有属性 'id'

这是我使用的代码:

from selenium import webdriver
from appium.webdriver.common.touch_action import TouchAction

caps = {}
caps["deviceName"] = "NVWCE6YSV47TGM8S"
caps["platformName"] = "Android"
caps["appPackage"] = "com.gradrix.quicklaunch"
caps["appActivity"] = "com.gradrix.quicklaunch.MainActivity"
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

time.sleep(5)
TouchAction(driver).tap([(104, 255)]).perform()
driver.quit()

【问题讨论】:

  • 你有一个出色的minimal reproducible example。我不确定人们为什么要关闭它。
  • 试试TouchAction(driver).tap(x=104, y=255).perform()tap 需要两个关键字而不是列表。
  • @MaximilianPeters 我更改了.tap(x=104, y=255) 而不是.tap([(104, 255)]),我得到了:KeyError: 'touchAction'。

标签: android python-2.7 coordinates appium


【解决方案1】:

这样对我有用:

# None - don't know why is needed but as I want to tap at coordinates and not an element, is None
# 104  - X coordinate
# 255  - Y coordinate
# 1    - this is the time of the tap action
TouchAction(driver).tap(None, 104, 255, 1).perform()

希望它有所帮助,并且您可以使用它

【讨论】:

  • 不能 100% 确定,但该设备似乎预计要轻按真手指的大小。这意味着当我试图靠近屏幕顶部时,在 y=10 或 50 px 处点击时,点击将不起作用。但是当点击大约在 200 像素左右时,它会正常工作(在 > 2000 像素高度的屏幕上)。当 y 很小的时候,也许我也在点击 android 的状态栏。谁知道如何计算Android状态栏的高度?
【解决方案2】:

改变

from selenium import webdriver

from appium import webdriver

【讨论】:

    猜你喜欢
    • 2019-08-08
    • 2022-01-07
    • 2020-01-02
    • 2016-02-03
    • 1970-01-01
    • 2011-09-29
    • 2015-03-08
    • 1970-01-01
    相关资源
    最近更新 更多