python - 无法使用monkeyrunner识别文本

标签 python monkeyrunner

我有一个脚本可以查找 TextView ,获取其坐标并单击它。为了单击,我必须滚动并找到该 TextView 。脚本如下,

text = 'abc'
self.device.drag((400,600), (300, 200), 0.01, 120)
tv = self.vc.findViewWithText(text)
if tv:
    (x, y) = tv.getXY()
    print >>sys.stderr, "Clicking TextView %s @ (%d,%d) ..." % (text, x, y)
    tv.touch()
else:
        print "Text is not found" %text

它可以拖动。尽管存在文本“abc”,但它会打印“未找到文本”。

我删除了drag()方法,并手动进行了拖动,它工作得很好(识别文本并进行了点击)。

谁知道我的drag()方法有什么问题吗?

谢谢

最佳答案

AndroidViewClient.dump() 转储当前显示在屏幕上的内容,因此如果您必须滚动才能使 TextView 可见,它不会出现在第一个中(隐式)转储。 因此,滚动后必须再次转储:

text = 'abc'
self.device.drag((400,600), (300, 200), 0.01, 120)
MonkeyRunner.sleep(3)
self.vc.dump()
tv = self.vc.findViewWithText(text)
if tv:
    (x, y) = tv.getXY()
    print >>sys.stderr, "Clicking TextView %s @ (%d,%d) ..." % (text, x, y)
    tv.touch()
else:
        print "Text is not found" %text

text = 'abc'
self.device.drag((400,600), (300, 200), 0.01, 120)
MonkeyRunner.sleep(3)
self.vc.dump()
self.vc.findViewWithTextOrRaise(text).touch()

另请考虑 NRP 提到的观点关于 sleep 。

关于python - 无法使用monkeyrunner识别文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13985678/

相关文章:

android - Android 上的黑猩猩聊天

android - 使用 Android viewClient 安装包

android - 带有机器人框架的 MonkeyRunner

android - MonkeyRunner的方法 "device.press"或 "device.touch"没有生效

python - 如何使用 PIL 获得日本文本到图像的正确输出?

python - Flask静态文件获取404

python - 值错误 : cannot reindex from a duplicate axis using isin with pandas

python - 如何防止向 ThreadPoolExecutor 提交过多作业?

python - Keras顺序时间分布模型2和3个序列之间的极值结果差异

java - Monkey Runner - 在 Java 类中使用它向模拟器发送命令