appium定位控件

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

元素的定位

滑动

1.首先获取整个屏幕的宽度和高度

•intwidth=driver.manage().window.getSize().width;

•intheight=driver.managet().window,getSize().height;

2.开始滑动:

•向上滑动:

•driver.swipe(width/2,height*3/4,width/2,height/4,during);

•向下滑动:

•driver.swipe(width/2,height/4,width/2,height*3/4,during);

•向左滑动:

•driver.swipe(width*3/4,height/2,width/4,height/2,during);

•向右滑动:

•driver.swipe(width/4,height/2,width*3/4,height/2,during);

点击

tap(self, positions, duration=None):

当控件无法获取时,那我们就可以使用坐标用tap方法做点击操作,而且tap方法可以用于多点点击。

WebElement 元素的常用方法

1. 点击方法      element.click()

2.元素是否被启用     element.isEnabled()

3.是否显示        element.isDisplayed()

4.是否选中(检查一个复选框或单选按钮被选中)       element.isSelected()

5.获取元素文本      element.getText()

6.获取高度           element.getSize().getHeight()

7.获取宽度           element.getSize().getWidth()

8.获取标签           element.getTagName()

9.元素左上角X轴            element.getLocation().getX();

10.元素左上角Y轴           element.getLocation().getY();

11.点击      intfingers(手指),intduration(持续)     driver.tap(2,2);

AppiumDriver 常用方法

1.获取当前使用的平台名称    driver.getAutomationName()

2.获取上下文     driver.getContext()driver.getContextHandles()

3.安装app     driver.installApp("D:\\apk\\base.apk");

4.App是否安装了      driver.isAppInstalled("com.example.android.contactmanager");

5.卸载app(卸载前要重置app状态)   driver.removeApp("com.example.android.contactmanager");

6.运行app     driver.launchApp();

7.关闭app     driver.closeApp();

8. 重置app状态(如果没有运行重置会出现异常)     driver.resetApp();

等待时间

隐式等待,此处的隐式等待是针对Driver,每次执行命令的 最长执行时间也可以理解为超时时间,一些人对此处有误解,认为是让Driver等一段时间,确实某些时候能让Driver等一段时间,

但是影响是全局的,每次Driver执行找不到元素都会等待此处设置的时间;

隐式等待:driver.manage().timeouts().implicitlyWait(second,TimeUnit.SECONDS);

显式等待,就是明确的要等到某个元素的出现或者是某个元素的可点击等条件,等不到,就一直等,除非在规定的时间之内都没找到,那么就跳出Exception.

WebElemente = (newWebDriverWait(chromeDriver,10)).until(newExpectedCondition(){

@Override

publicWebElementapply(WebDriverd) {

returnd.findElement(By.id("id"));}});

AndroidDriver 常用方法(文件传送、截图)

9.本地文件推送到手机(远程路径,本地路径)

driver.pushFile("/data/local/tmp/logs.log",newFile("D:\\logs.log"));

10.截图:

Filefile=driver.getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(file,newFile("D:\\AutoScreenCapture\\file.png"));

11.异常截图

FilescreenShotFile= ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

try{

FileUtils.copyFile(screenShotFile,newFile("D:\\AutoScreenCapture\\"+".png"));

}catch(IOExceptione) {

e.printStackTrace();

}



 

猜你喜欢

转载自blog.csdn.net/qqGHJ/article/details/102746600
今日推荐