appium常用方法

1、选择一个控件并进行点击的方法:
driver.findElement(By.id("com.xx.mobile.socialwidget:id/contact_container")).click();
 

2、如果我们需要点击列表中的某一个元素,或者一个界面有多个同种控件时点击指定一个控件的方法:

List elements = driver.findElements(By.id("com.xx.mobile.socialsdk:id/list_item_title"));
for(WebElement element : elements){
if(element.getText().equals("Mg004nick")){
element.click();
}
}
 
3、每步自动化点击之间都需要sleep一下,这个方法为:
try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace(); 
}
 
4、界面上进行滑动的方法:
int width = driver.manage().window().getSize().width;
int height = driver.manage().window().getSize().height;
driver.swipe(width*4/5, height*3/4, width*1/5, height*3/4, 1000);
 
5、使用坐标进行点击的方法:
TouchAction gesture = new TouchAction(driver).press(width/2, height/2).release();
driver.performTouchAction(gesture);
 
6、输入数据的方法:
有两种方式:
(1)可以通过WebElement的方式editElement.sendKeys("12");
(2)对于一些H5页面,可以使用commonUtil.executeCmd("adb shell input text 12");
 
7、点击H5页面的元素:
webOperator.switchtoWeb(driver);      切换到WEBVIEW模式
WebElement webLink = driver.findElement(By.partialLinkText("下一步"));
 int gestureX = webLink.getLocation().getX();
int gestureY = webLink.getLocation().getY();
webOperator.switchtoNative(driver);   切换到NATIVE模式
TouchAction gesture = new TouchAction(driver).press(gestureX, gestureY).release();
driver.performTouchAction(gesture);
 
8、定位H5元素时,可以使用chrome://inspector获取页面信息,但是网络必须是越狱的,不然获取到的是空白页面
 
参考:http://blog.sina.com.cn/s/blog_628cc2b70102vtk3.html
posted @ 2017-08-30 11:03  得那些过往  阅读(263)  评论(0编辑  收藏  举报