首页导航左右滑动操作(X轴变),上下滑动(Y轴变)
public static void swipe(){
//X 轴起点为650,终点为50,Y轴设置坐标为800,每次间隔为1秒
driver.swipe(900,800,100,800,1000);
System.out.println("滑动第一次");
driver.swipe(900,800,100,800,1000);
System.out.println("滑动第二次");
driver.swipe(900,800,100,800,1000);
System.out.println("滑动第三次");
}
首页导航滑动操作改进
public static void swipe() throws InterruptedException{
//先获取宽,也就是X轴的最大长度
int width=driver.manage().window().getSize().width;
system.out.println("获得屏幕宽度是"+width);
//先获取高,也就是Y轴的最大值
int height=driver.manage().window().getsize()height;
system.out.println("获得屏幕高度是"+height);
system.out.println("起点坐标是"+width*9/10+","+height/2+"终点坐标是"+width/20);
driver.swipe(width*9/10,height/2,width/20,height/2,1000);
System.out.println("滑动第一次");
}
注:手机坐标认识(坐标原点:左上角)
控件的第二次封装
eg:
public static void Page_huadong(String data){
//先获取宽,也就是X轴的最大值
int width=driver.manage().window().getSize().wdith;
//再获取高,也就是Y轴的最大值
int height=driver.manage().wdith().getSize().height;
if(data.equals(“左滑”)){
//左滑时X轴起点大于终点
driver.swipe(width*9/10,height/2,width/20,height/2,1000);
}
if(data.equals(“右滑”)){
//右滑时X轴起点小于终点
driver.swipe(width/10,height/2,width*9/10,height/2,1000);
}
if(data.equals(“上滑”)){
//上滑时Y轴起点大于终点
driver.swipe(width/2,height*9/10,width/2,height/20,1000);
}
if(data.equals(“下滑”)){
//下滑时Y轴起点小于终点
driver.swipe(width/2,height/20,width/2,height*9/10,1000);
}
}