[英]Android: How to programatically login to website and retrieve data from it?
[英]Android: How to programatically detect google login popup in Android devices
我試過以下monkeyrunner腳本:
#!/usr/bin/env monkeyrunner
from __future__ import with_statement
import logging
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from com.android.monkeyrunner.easy import EasyMonkeyDevice
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
if __name__ == '__main__':
udid = '02f4e07008e40dfc' #sys.argv[1]
device = MonkeyRunner.waitForConnection(60, udid)
easyDevice = EasyMonkeyDevice(device)
logger.info(easyDevice.getFocusedWindowId())
#h = device.getHierarchyViewer()
#w = h.getFocusedWindowName()
#logger.info(w)
但我得到:
File "./detectGoogleLoginPopup.py", line 19, in <module>
easyDevice = EasyMonkeyDevice(device)
java.lang.RuntimeException: Could not connect to the view server
我現在有一種ocr
方式來解決這個問題,但是會喜歡一個Monkeyrunner或基於Java api的解決方案。
使用AndroidViewClient / culebra,您可以輕松檢測包含焦點的窗口中是否包含包含You typed an incorrect password...
的文本的View(即使使用正則表達式):
vc.findViewWithText('You typed an incorrect password.*')
我認為這將解決您的問題。
獲取當前顯示的活動的一種方法是使用命令
device.shell('dumpsys window displays')
並按Application tokens in Z order:
找到“ Application tokens in Z order:
”行Application tokens in Z order:
的下一行類似於:
App #6 AppWindowToken{42d89c20 token=Token{428ffac0 ActivityRecord{419ec3e8 u0 com.andrew.apollo/.ui.activities.HomeActivity t106}}}:
您可以使用python進行解析,以提取當前活動(在本例中為com.andrew.apollo/.ui.activities.HomeActivity
。
另一種方法是使用命令
device.shell('dumpsys activity activities')
並找到“ Running activities (most recent first):
”行Running activities (most recent first):
接下來的幾行看起來像這樣:
TaskRecord{428f0e90 #106 A=com.andrew.apollo.task U=0 sz=1}
Run #3: ActivityRecord{419ec3e8 u0 com.andrew.apollo/.ui.activities.HomeActivity t106}
再次,您可以使用python解析以獲取com.andrew.apollo/.ui.activities.HomeActivity
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.