Object search-class name and package name
First, class Name property anchored object
| return value |
Api |
Describe |
| Uiselector |
Calssname (String className) |
Full class name matching |
| Uiselector |
Calssnamematches (String regex) |
Regular class name matching |
Quick way to write search criteria
1) Component name. Class.getname Way
2) Full class name method: Android.widget.LinearLayout
3) Regular mode
4) Constant mode
Second, the package Name property to locate the object
| return value |
Api |
Describe |
| Uiselector |
PackageName (String name) |
Package name complete Match |
| Uiselector |
Packagenamematches (String name) |
Regular package name matching |
Note: Using the package name object is generally used to get the first child element of the clicked parent class
Third, API application examples:
PackageCom.testuiselector;ImportAndroid.view.View;ImportCom.android.uiautomator.core.UiDevice;ImportCom.android.uiautomator.core.UiObject;Importcom.android.uiautomator.core.UiObjectNotFoundException;ImportCom.android.uiautomator.core.UiSelector;Importcom.android.uiautomator.testrunner.UiAutomatorTestCase; Public classDemo1extendsUiautomatortestcase {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubString jarname, TestClass, testname, Androidid; Jarname= "Demo1"; TestClass= "Com.testuiselector.Demo1"; TestName= "Testclassandpackage"; Androidid= "1"; NewUiautomatorhelper (Jarname, TestClass, testname, Androidid); } Public voidTestclassandpackage ()throwsuiobjectnotfoundexception{uidevice.getinstance (). Presshome (); Sleep (1000); //Exact MatchUiselector l1=NewUiselector (). ClassName ("Android.view.View"). Instance (3); UiObject Clock1=NewUiObject (L1); Clock1.click (); Sleep (1000); Uidevice.getinstance (). Pressback (); Sleep (1000); //regular MatchUiselector l2=NewUiselector (). Classnamematches (". *view"). Instance (4); UiObject Clock2=NewUiObject (L2); Clock2.click (); Sleep (1000); Uidevice.getinstance (). Pressback (); Sleep (1000); //Class.getname ()Uiselector l3=NewUiselector (). ClassName (View.class. GetName ()). Instance (3); UiObject Clock3=NewUiObject (L3); Clock3.click (); Sleep (1000); Uidevice.getinstance (). Pressback (); }}Demo1.java
Android Wireless test-uiautomator Uiselector API Introduction VI