1.無法模擬 點(diǎn)擊 事件
機(jī)型:小米max
self.driver.find_element_by_Id("id").click() ? ? 無效
解決辦法:在開發(fā)者選項(xiàng)中逛揩,開啟 ? ??USB調(diào)試(安全設(shè)置) ??選項(xiàng) ?或者沒有開啟允許點(diǎn)擊設(shè)置
2.appium無法向Android輸入中文字符
在desired_caps連接手機(jī)代碼中加入一下代碼:
desired_caps['unicodeKeyboard']=True
desired_caps['resetKeyboard']=True
完整代碼如下:
def ?get_driver(self):
? ? ? ? ? ? ? desired_caps={}
? ? ? ? ? ? ? desired_caps['platformName'] ='android'
? ? ? ? ? ? ? desired_caps['platformVersion'] ='4.4.2'
? ? ? ? ? ? ? desired_caps['deviceName'] ='Android Emulator'
? ? ? ? ? ? ? desired_caps['appPackage'] =appPackage ? #(你的app包名)
? ? ? ? ? ? ? desired_caps['appActivity'] =appActivity ? ? ? ? ?#(你的appActivity名)
? ? ? ? ? ? ? desired_caps['unicodeKeyboard']=True
? ? ? ? ? ? ? desired_caps['resetKeyboard']=True
? ? ? ? ? ? ? self.driver=webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
? ? ? ? ? ? ? return ? self.driver
但是在安卓7.0上會(huì)報(bào)錯(cuò):
Attempt to re-install io.appium.android.ime without first uninstalling
1. 解決辦法:
取消重新安裝IME.APK
找到該目錄下js文件: Appium\node_modules\appium\lib\devices\android\android-common.js
androidCommon.pushUnicodeIME=function(cb){
cb()? ? ? ? ? ? ? ? (添加這個(gè)方法)
/*? logger.debug("Pushing unicode ime to device...");??
var imePath = path.resolve(__dirname, "..", "..", "..", "build",? ? ? "unicode_ime_apk", "UnicodeIME-debug.apk");
? fs.stat(imePath, function (err) {? ?
?if (err) {??
? ? cb(new Error("Could not find Unicode IME apk; please run " +? ? ? ? ? ? ? ? ? "'reset.sh --android' to build it."));?
?? } else {? ? ? this.adb.install(imePath, false, cb);??
? }??
}.bind(this));??
*/
(注釋以上代碼)
};