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<AndroidElement> 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<AndroidElement> 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);

    }









本文转自 知止内明 51CTO博客,原文链接:http://blog.51cto.com/357712148/2048587,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值