appium java动态等待_appium-java简单判断操作

/***

* 名片设置删除好友 不看他/她的动态 用例 1、点击我的、 2、点击设置 3、判断列表是否有,如果有就删除,如果没有就添加好友!!

*

*/

public static void MoveFirends() throws Exception {

Thread.sleep(2000);

driver.findElement(GetByLocator.getLocator("MyInfo")).click();

Thread.sleep(2000);

driver.findElement(GetByLocator.getLocator("BusinessCardSet")).click(); // 设置

driver.findElement(GetByLocator.getLocator("DoNotLookDynamic")).click(); // 点击不看他/她的动态

List AddNameList = driver.findElements(GetByLocator.getLocator("AddNameList"));

if (AddNameList == null || AddNameList.size() == 0) {

System.out.println("不看他/她的动态列表有没有可以删除的朋友");

driver.findElement(GetByLocator.getLocator("AddBusinessCard_DonWatch")).click();// 添加名片

driver.findElement(GetByLocator.getLocator("BusinessCardCearch")).click();// 添加名片

driver.findElement(GetByLocator.getLocator("SearchBoxTextInput")).sendKeys("美丽的开始"); // 输入要添加的名片

driver.findElement(GetByLocator.getLocator("SelectTheSearchResults")).click(); // 选中添加

driver.findElement(GetByLocator.getLocator("Click_ok")).click(); // 确定

System.out.println("添加名片成功");

driver.pressKeyCode(AndroidKeyCode.BACK);

} else {

for (AndroidElement as : AddNameList) {

String namelist = as.getAttribute("text");

System.out.println("AddNameList:" + namelist);

if (!namelist.equals("")) {

driver.findElement(GetByLocator.getLocator("MoveBusinessCard_DonWatch")).click();

driver.findElement(GetByLocator.getLocator("BackgroundOK")).click();

System.out.println("不看他/她的动态列表有可以删除的朋友");

System.out.println("开始移除不看他/她的动态列朋友!");

}

}

}

System.out.println("不看他/她的动态列表操作完毕!!");

driver.pressKeyCode(AndroidKeyCode.BACK);

}

参考 沙陌 老师 资料

/**

* 1. 首页点击文章标题

* 2. 进入文章详情页面点击关注

* 3. 如果是已关注,则取消关注

* 4. 遍历当前界面所有的文章

* @param args

* @throws Exception

* @throws Exception

*/

public void attention() throws Exception{

//*[@resource-id='com.zhihu.android:id/title']

List titleList=driver.findElementsByXPath("//*[@resource-id='com.zhihu.android:id/title']");

for(AndroidElement ae:titleList){

String title=ae.getText();

ae.click();

//*[@text='已关注'] //*[@text='关注']

Thread.sleep(2000);

try {

driver.findElementByXPath("//*[@text='已关注']").click();

System.out.println(title+"====关注取消成功");

} catch (Exception e) {

// TODO: handle exception

try {

driver.findElementByXPath("//*[@text='关注']").click();

System.out.println(title+"====关注成功");

} catch (Exception e2) {

// TODO: handle exception

System.out.println("没找到关注,继续执行");

}

}

Thread.sleep(2000);

//执行设备物理返回

driver.pressKeyCode(4);

Thread.sleep(1000);

}

}

public void nightMode(){

clickMenu(5);

AndroidElement nightMode=driver.findElement(By.id("com.zhihu.android:id/night_mode_switch"));

String status=nightMode.getAttribute("checked");

nightMode.click();

status=nightMode.getAttribute("checked");

if(status.equals("true")){

System.out.println("夜间模式打开成功");

}else{

System.out.println("夜间模式关闭成功");

}

String text=nightMode.getAttribute("text");

String id=nightMode.getAttribute("resourceId");

String className=nightMode.getAttribute("className");

//String content_desc=nightMode.getAttribute("content-desc");

String checkable=nightMode.getAttribute("checkable");

String clickable=nightMode.getAttribute("clickable");

String enable=nightMode.getAttribute("enabled");

String longClickable=nightMode.getAttribute("longClickable");

//name参数优先获取content-desc属性的值,如果这个值为空字符串,那么会获取text属性的值

String name=nightMode.getAttribute("name");

//更新AppiumBootStrap包之后,可以实用contentDescription来获取content-desc的值

//String content_desc=nightMode.getAttribute("contentDescription");

String selected=nightMode.getAttribute("selected");

String displayed=nightMode.getAttribute("displayed");

//nightMode.isSelected();//这个方法没用,无法是否被选中

System.out.println(selected+"============="+displayed);

}

你可能感兴趣的:(appium,java动态等待)