Appium 相关学习(三) 使用webdriver截图以及app点击事件

1、使用webdriver执行截图,也可以在此方法中自定义文件位置,需要通过操作File格式移动

//使用driver工厂创建driver
AppiumDriver driver=DriverFactory.getDriver();    
//执行截图,生成file文件,文件默认保存位置为系统当前账户的TEMP文件夹下,格式为png
File file=driver.getScreenshotAs(OutputType.FILE);

2、app的点击事件,点击分为  直接点击  和   滑动

  点击事件分为:TouchAction  MultiTouchAction   也可以使用webdriver直接点击

  TouchAction点击方法为tap,有以下重载方法:

  tap(WebElement)  :点击元素。

  tap(int x,int y)  :点击固定坐标,此坐标相对屏幕。

  tap(WebElement,int x,int y)  :点击按钮的偏移量,基于按钮的location计算

  

WebElement weAdd=this.driver.findElementByName("Add Contact");
//创建TouchACTION
TouchAction touch=new TouchAction(this.driver);
//直接点击控件
touch.tap(weAdd);
//点击坐标
touch.tap(weAdd.getLocation().x+1, weAdd.getLocation().y+1);
//点击控件上的坐标
touch.tap(weAdd,weAdd.getLocation().x+1, weAdd.getLocation().y+1);

  MultiTouchAcion  多点触控

  

//将以上点击事件同时添加到多点触控中执行
multiTouch.add(touch).perform();

  

  driver直接触控 

  this.driver.tap(int , WebElement, int);  多点触控控件,并可控制点击事件

  

//触控点为 1  ,点击控件为 weAdd ,触控事件为 500ms
this.driver.tap(1, weAdd, 500);


  this.driver.tap(arg0, arg1, arg2, arg3);

//触控点为 1,触控坐标为 x, y ,  触控事件为500ms
this.driver.tap(1, weAdd.getLocation().x, weAdd.getLocation().y, 500);

    

   2、滑动swipe

          webdriver.swipe(int x1,int x2,int x3,int x4,int duration)   坐标1(x1,y1)  滑动到坐标2(x2,y2) 滑动停留时间duration

原文地址:https://www.cnblogs.com/LeeForLeslie/p/5014167.html