恭喜发财dife 发表于 2018-2-24 09:47:18

Appium——appium安卓常规元素定位

1、UIAutomatorViewer
下载adt压缩文件

1、UIAutomatorViewer路径:

adt-bundle-windows-x86_64-20140321\sdk\tools

2、连接真机后,adb devices 确认获取到该手机

双击uiautomatorviewer.bat文件打开

2、WebElement定位

1、Name定位

driver.findElementByName("大神");

driver.findElement(By.name("大神"));

2、Id定位

driver.findElementById("com.cwvs.jdd:id/rb_huodong");

driver.findElement(by.id("com.cwvs.jdd:id/rb_huodong"));、

3、classname定位

List<WebElement> lis = driver.findElementsByClassName("android.widget.RadioButton");

WebElement element = lis.get(2);

4、xpath定位

driver.findElementByXPath("//android.widget.RadioButton[@text='大神']");

5、组合定位

List<WebElement> lis =null;

lis = driver.findElementsByAndroidUIAutomator

("new UiSelector().className("+classname+").index("+index+").clickable(true)");

6、坐标定位

driver.tap(1, 550, 1835, 500);//坐标(550,1835)坐标点击1次,500毫秒

3、appium常用操作

1、driver.findElementById(Id).sendKeys(key);//输入文本内容

2、driver.findElementById(id).click();            //点击某个元素

3、driver.findElementById(id).getText();         //获取文本内容

4、driver.tap(fingers,int i, int j,int duration);    //点击坐标多久几次

5、driver.tap(fingers,WebElement i,int duration);    //点击元素多久几次

6、driver.swipe(i, j, k, h, during);                  //滑动坐标多久

7、Assert.assertEquals(actual,expected);   //断言,判断内容是否相等

8、driver.sendKeyEvent(n);                           //66回车,4后退

梦想家 发表于 2018-2-28 16:02:19

:handshake
页: [1]
查看完整版本: Appium——appium安卓常规元素定位