我可以用 Monkeyrunner 读取按钮上的标签吗
一般来说,我想编写一个 Monkeyrunner 程序来打开我的 Android 手机上的 Wifi(如果尚未打开)。我有以下代码:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
package='com.android.settings'
activity='.Settings'
component_name=package + "/" + activity
device = MonkeyRunner.waitForConnection()
device.startActivity(component=component_name)
device.press('KEYCODE_DPAD_CENTER', "DOWN_AND_UP")
device.press('KEYCODE_DPAD_DOWN')
device.press('KEYCODE_DPAD_DOWN')
device.press('KEYCODE_DPAD_DOWN')
device.press('KEYCODE_DPAD_CENTER', "DOWN_AND_UP")
device.press('KEYCODE_DPAD_CENTER', "DOWN_AND_UP")
此代码导航到检测到 wifi 网络的屏幕。当我向下滚动时,我想检查当前按钮是否适用于我的网络,如果适用且未打开,请将其打开。
我的一个想法是阅读按钮上的标签进行比较。任何帮助表示赞赏。
In general I want to write a monkeyrunner program that turns on Wifi on my android phone if it's not on already. I have the following code:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
package='com.android.settings'
activity='.Settings'
component_name=package + "/" + activity
device = MonkeyRunner.waitForConnection()
device.startActivity(component=component_name)
device.press('KEYCODE_DPAD_CENTER', "DOWN_AND_UP")
device.press('KEYCODE_DPAD_DOWN')
device.press('KEYCODE_DPAD_DOWN')
device.press('KEYCODE_DPAD_DOWN')
device.press('KEYCODE_DPAD_CENTER', "DOWN_AND_UP")
device.press('KEYCODE_DPAD_CENTER', "DOWN_AND_UP")
This code navigates to the screen where the wifi networks are detected. As I scroll down I want to check to see if the current button is for my network and if it is, and is not turned on, turn it on.
One thought I had was to read the label on the button for comparison. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这篇文章(monkeyrunner:与视图交互),同时不包含您问题的确切答案,应该为您提供使用 AndroidViewClient。
This post (monkeyrunner: interacting with views), while doesn't contain the exact answer to your question, should give you the hints to solve your problem using AndroidViewClient.
有两种方法可以实现此目的。两者都涉及使用 Monkeyrunner result = device.takeSnapshot() 保存图像。
首先,您可以使用 MonkeyImage.sameAs() 来比较两个图像,但要做到这一点,您需要在不重新启动monkeyrunner的情况下获取两个图像,因为无法加载保存的monkeyimaged。
另一种方法涉及使用诸如 http://sikuli.org/ 之类的内容来比较两个图像。
There are two ways that you could accomplish this. Both involve saving images using monkeyrunner result = device.takeSnapshot().
First you could use MonkeyImage.sameAs() to compare the two images, but to do this you would need to get both two images without restarting monkeyrunner as there is no way to load a saved monkeyimaged.
The other way involves using something like http://sikuli.org/ to compare the two images.
解决方法是-
您可以使用android中的>添加网络选项,给出您想要连接的网络名称。它应该会自动连接到添加的网络。
a workaround is-
you can make use of >Add Network option in android,Give the network name you want to connect.It should automatically connect to the added network.