MR_ Android view client source code(3)---获取当前view id的名称

#!/usr/bin/env monkeyrunner
# -*- coding:utf-8 -*-
'''
Copyright (C) 2012  Diego Torres Milano
Created on Feb 3, 2012

@author: diego
'''
import sys
import os

# this must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails
#Actual device serialno=emulator-5554
try:
    ANDROID_VIEW_CLIENT_HOME = os.environ['ANDROID_VIEW_CLIENT_HOME']
except KeyError:
    print >>sys.stderr, "%s: ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment" %    __file__
    sys.exit(1)
sys.path.append(ANDROID_VIEW_CLIENT_HOME + '/src')

from com.dtmilano.android.viewclient import ViewClient
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner as mr, MonkeyDevice as md
#starting script
print "start"
# Connects to the current device, returning a MonkeyDevice object
device, serialno = ViewClient.connectToDeviceOrExit(30,"emulator-5554")
#device connected
print "connection started"

# sets a variable with the package's internal name
package = 'com.tuangoui.taobao'
# sets a variable with the name of an Activity in the package
activity = '.activities.StartActivity'
# sets the name of the component to start
runComponent = package + '/' + activity
# Runs the component
device.startActivity(component=runComponent)
#device set to sleep for 4 seconds
print "wait for 10 seconds"
# first screen shot event
mr.sleep(10);


vc = ViewClient(device, serialno)
vc.dump()
root = vc.getRoot()

for i in range(1,50):
    id_list=vc.findViewByIdOrRaise('id/no_id/%d'%i)

    print id_list.getText().encode("utf-8")



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值