appium使用技巧

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qqGHJ/article/details/102746307

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获取页面信息,但是网络必须是越狱的,不然获取到的是空白页面,如下图:

猜你喜欢

转载自blog.csdn.net/qqGHJ/article/details/102746307