Tag Archives: appium

[Solved] appium Error: A new session could not be created

Error reported in appium:

selenium. common. exceptions. SessionNotCreatedException: Message: A new session could not be created. (Original error: Command failed: C:\\WINDOWS\\system32\\cmd.exe /s /c “D:\\tools\\Android\\android-sdk\\platform-tools\\adb.exe -s 127.0.0.1:62001 shell “ps ‘uiautomator'””

Execute the command in the error message in CMD:

The error message reported is: bad PID ‘uiautomator’

Solution:

1. Find ADB.JS file In the appium installation directory. directory:\appium\node_modules\appium\node_Modules\appium-ADB\lib
2. Open ADB.JS, find the following code:

ADB.prototype.shell = function (cmd, cb) {
  if (cmd.indexOf('"') === -1) {
    cmd = '"' + cmd + '"';
  }
  var execCmd = 'shell ' + cmd;
  this.exec(execCmd, cb);
};

3. Add the following code below the above code

//add
ADB.prototype.shell_grep = function (cmd, grep, cb){
    if (cmd.indexOf('"') == -1){
        cmd = '"' + cmd + '"';
    }
    var execCmd = 'shell' + cmd + '| grep ' + grep;
    this.exec(execCmd, cb);
};

4. Find the following code:

ADB.prototype.getPIDsByName = function (name, cb) {
  logger.debug("Getting all processes with '" + name + "'");
  this.shell("ps '" + name + "'", function (err, stdout) {
    if (err) return cb(err);
    stdout = stdout.trim();
    var procs = [];
    var outlines = stdout.split("\n");
    _.each(outlines, function (outline) {
      if (outline.indexOf(name) !== -1) {
        procs.push(outline);
      }
    });
    if (procs.length < 1) {
      logger.debug("No matching processes found");
      return cb(null, []);
    }
    var pids = [];
    _.each(procs, function (proc) {
      var match = /[^\t ]+[\t ]+([0-9]+)/.exec(proc);
      if (match) {
        pids.push(parseInt(match[1], 10));
      }
    });
    if (pids.length !== procs.length) {
      var msg = "Could not extract PIDs from ps output. PIDS: " +
                JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs);
      return cb(new Error(msg));
    }
    cb(null, pids);
  });
};

4. Comment out the above code, start with/* and end with */comment

5. Replace with the following code

//replace
ADB.prototype.getPIDsByName = function (name, cb) {
  logger.debug("Getting all processes with '" + name + "'");
  this.shell_grep("ps", name, function (err, stdout) {
    if (err) {
      logger.debug("No matching processes found");
      return cb(null, []);
    }
    var pids = [];
    _.each(procs, function (proc) {
    var match = /[^\t ]+[\t ]+([0-9]+)/.exec(proc);
    if (match) {
    pids.push(parseInt(match[1], 10));
    }
    });
    if (pids.length !== procs.length) {
      var msg = "Could not extract PIDs from ps output. PIDS: " +
      JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs);
      return cb(new Error(msg));
    }
    cb(null, pids);
  });
};

6. Restart appium

[Solved] appium Environment Build appium-doctor –ios Command Error

In the process of building appium environment, various errors will appear when running appium doctor — IOS command.

Error 1: dB and IDB_companion are not installed

Solution:

1. Update MAC system and Xcode software

2. Run command

brew tap facebook/fb
brew install idb-companion
pip install fb-idb

Just.

Error 2: opencv4nodejs cannot be found

1. Install cmake and check the version

cmake -version

2. Run command

npm -g install opencv4nodejs --ignore-scripts

Just.

Appium Error: An unknown server-side error occurred while pro…g\\\\npm\\\\node_modules\\\\appium\\\\node_modules

Error Messages:

adb.exe' -P 5037 -s 29cc0bc8 shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Exception occurred while executing 'delete': java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTI

 

Solution:

In Developer Options – Disable Permission Monitoring – Enabled

[Solved] appium Error: Message: Cannot set the element to ‘XXXX’. Did you interact with the correct element?

appium+python+android

There was a problem locating the module input

send_Keys error

Appium reports an error message: cannot set the element to ‘XXXX’. Did you interact with the correct element?

I checked the information and said it was due to the module attribute of Android

The module attribute that can be entered is android.widget.edittext

However, because the module attribute I need to enter is not this attribute, send_ Keys failed

Also tried get_Value() and other input methods are not feasible

Currently, no method is found to use send_keys, Look at what others say you can locate through uiautomator (you can try if you haven’t tried)

At present, the place I encounter is login, so I use driver.press_Keycode() method, input through Unicode keyboard, but presskeycode needs key code, which is more troublesome.

The following is the positioning and use of uiautomator given by netizens

driver.find_element_by_android_uiautomator('new UiSelector().text("Positioning Properties")').send_keys('Input content')