zoukankan      html  css  js  c++  java
  • appium 二次切换webview后无法找到页面元素

    问题:在使用Appium进行android自动化测试时,第一次切换webview可以正常找到元素,但切换到NATIVE_APP后,再次切换到webview时,appium就无法定位元素,且等待一段时间后,自动退出执行。

    原因为:Appium第一次切换到Html页面时,会新生成一个Chromedriver;当第二次切换到Html时,会使用已经存在的Chromedriver。

    解决方式:

      找到AppiumAppium ode_modulesappiumlibdevicesandroid目录下的android-hybrid.js文件,找到如下代码

    androidHybrid.startChromedriverProxy = function (context, cb) {
      cb = _.once(cb);
      logger.debug("Connecting to chrome-backed webview");
      if (this.chromedriver !== null) {
        return cb(new Error("We already have a chromedriver instance running"));
      }
    
      if (this.sessionChromedrivers[context]) {
          //in the case where we've already set up a chromedriver for a context,'
          //we want to reconnect to it, not create a whole new one
          this.setupExistingChromedriver(context, cb);
        } else {
          this.setupNewChromedriver(context, cb);
        }
       
    };
    

      

    然后,修改如下:

    androidHybrid.startChromedriverProxy = function (context, cb) {
      cb = _.once(cb);
      logger.debug("Connecting to chrome-backed webview");
      if (this.chromedriver !== null) {
        return cb(new Error("We already have a chromedriver instance running"));
      }
    
      // 修改时间:2018-07-23  目的:二次切换webview后,chromeDriver未重新生成,无法定位元素
      // if (this.sessionChromedrivers[context]) {
      //   // in the case where we've already set up a chromedriver for a context,
      //   // we want to reconnect to it, not create a whole new one
      //   this.setupExistingChromedriver(context, cb);
      // } else {
       //   this.setupNewChromedriver(context, cb);
       // }
       this.setupNewChromedriver(context,cb);
      // 修改时间:2018-07-23  目的:二次切换webview后,chromeDriver未重新生成,无法定位元素
    };
    
  • 相关阅读:
    【VB编程】05.MsgBox与InputBox函数
    【VBA编程】04.使用自定义数据类型
    【VBA编程】03.判断输入年份是否是闰年
    ubuntu终端颜色设置
    常用命令
    adbd cannot run as root in production builds的解决方法
    camera table表编译
    [Linux]history 显示命令执行的时间
    ubuntu下动态链接库的编译和使用实例
    xxx is not in the sudoers file.This incident will be reported.的解决方法
  • 原文地址:https://www.cnblogs.com/JcHome/p/9429717.html
Copyright © 2011-2022 走看看