我正在自动化Google注册,我遇到了一个问题......
作为注册的一部分,您需要登录Wi-Fi,然后等待直至连接。输入Wi-Fi凭证后,我会在while循环中等待屏幕更改:
print("Waiting for Wi-Fi to connect...")
while vc.findViewWithText("Select Wi-Fi") is not None:
MonkeyRunner.sleep(5)
vc.dump()
print("In Connecting...")
while vc.findViewWithText("Connecting") is not None:
MonkeyRunner.sleep(5)
vc.dump()
print("Connected")
MonkeyRunner.sleep(1)
有时这种方法有效,有时则不然。当它不起作用时,我收到以下错误:
Waiting for Wi-Fi to connect...
package="com.android.settings" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[332,1248][396,1312]" /><node index="1" text="Other network" class="android.widget.TextView" package="com.android.settings" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[426,1255][2196,1304]" /></node></node></node></node></node></node></node></node></node></node></hierarchy>
there are 65 views in this dump
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.FrameLayout id=id/no_id/1 ] parent=None has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/2 ] parent=android.widget.FrameLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.FrameLayout id=id/no_id/3 ] parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/4 ] parent=android.widget.FrameLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/5 ] parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/6 ] parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.FrameLayout id=id/no_id/7 ] parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.RelativeLayout id=id/no_id/8 ] parent=android.widget.FrameLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.RelativeLayout id=id/no_id/9 ] parent=android.widget.RelativeLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.LinearLayout id=id/no_id/10 ] parent=android.widget.RelativeLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: checking if root=View[ class=android.widget.TextView id=id/no_id/11 ] parent=android.widget.LinearLayout has attr=text == Select Wi-Fi
__findViewWithAttributeInTree: FOUND: View[ class=android.widget.TextView id=id/no_id/11 ] parent=android.widget.LinearLayout
received 9 chars
Killed
130621 11:22:03.616:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
130621 11:22:03.616:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 824, in <module>
main()
File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 802, in main
do_registration(vc, device)
File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 703, in do_registration
login_to_wifi(vc, device, wireless_ap_name, wireless_pw)
File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 783, in login_to_wifi
vc.dump()
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1780, in dump
self.setViewsFromUiAutomatorDump(received)
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1530, in setViewsFromUiAutomatorDump
self.__parseTreeFromUiAutomatorDump(received)
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1688, in _ViewClient__parseTreeFromUiAutomatorDump
self.root = parser.Parse(receivedXml)
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 988, in Parse
parserStatus = parser.Parse(uiautomatorxml, 1)
File "/home/allen/android/android-sdks/tools/lib/jython-standalone-2.5.4-rc1.jar/Lib/xml/parsers/expat.py", line 212, in Parse
xml.parsers.expat.ExpatError: Content is not allowed in prolog.
我是否错误地使用了API,或者是否有可用于检查Wi-Fi连接状态的MonkeyRunner / AndroidViewClient方法?