appium 二次切換webview后無法找到頁面元素


問題:在使用Appium進行android自動化測試時,第一次切換webview可以正常找到元素,但切換到NATIVE_APP后,再次切換到webview時,appium就無法定位元素,且等待一段時間后,自動退出執行。

原因為:Appium第一次切換到Html頁面時,會新生成一個Chromedriver;當第二次切換到Html時,會使用已經存在的Chromedriver。

 

解決方式:

  找到Appium\Appium\node_modules\appium\lib\devices\android目錄下的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未重新生成,無法定位元素
};

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM