zoukankan      html  css  js  c++  java
  • APPium+java如果找到这个元素则继续执行下面的元素,实现方法

    方法

    import org.openqa.selenium.By;
    import org.openqa.selenium.NoSuchElementException;

    public class Chazhaoyuansu {
        
        /**
         * 如果找到这个元素则继续执行下面的元素,找不则返回失败false,返回布尔值
         * @param by
         * @param waitTimes
         * @return
         */
        public static boolean whetherElementVisable(final By by, int waitTimes) {
            for (int attempt = 0; attempt < waitTimes; attempt++) {  
                try {
                    return true;
                } catch (NoSuchElementException e) {
                    if (attempt == waitTimes - 1) {
                        return false;
                    }
                }
            }
            return false;
        }
        
        
    }

    调用

     //如果有协议弹窗,则点击同意
            if (Chazhaoyuansu.whetherElementVisable(By.id("com.cmcc.p.poc:id/tv_title"), 1)) {
                //点击同意
                androidDriver.findElementById("com.cmcc.p.poc:id/tv_confirm").click();
            }else {
                //点击不同意
                androidDriver.findElementById("com.cmcc.p.poc:id/tv_cancel").click();
            }

  • 相关阅读:
    MOSS 2013研究系列动态修改WebConfig(上) 欧阳锋
    MOSS 2013研究系列MOSS 2013安装篇 欧阳锋
    GPIO
    [转]vi/vim使用进阶: 在VIM中使用GDB调试 – 使用pyclewn
    建立openwrt虚拟环境
    ebtables基本使用
    LFS小记
    Autoconf & Automake使用小记
    Packet Filter小记
    Web技术整理
  • 原文地址:https://www.cnblogs.com/tiansc1/p/15704086.html
Copyright © 2011-2022 走看看