我有一个脚本可以查找 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/