Mr _ Android view client source code (3)-Get the name of the current view ID

Source: Internet
Author: User

#! /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 ']
Failed t 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 ")

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.