Appium Android 真机 sendkeys 输入问题

dadda · 2017年07月24日 · 最后由 dadda 回复于 2017年07月28日 · 1216 次阅读

环境:mac + appium1.65
在 Android 真机上每次输入后,自动删除一部分,光标移到最左边再自动输入,如果没删除完的话,输入就是错误的了。
尝试了加一个清空,但是没起作用,哪位大神帮个忙?

共收到 5 条回复 时间 点赞

# 清空文本框原有内容
def edittextclear(self, text):
'''
清除 EditText 文本框里的内容
@param:text 要清除的内容
'''
# 光标移动到末尾键
self.driver.press_keycode(123)
for i in range(0, len(text)):
# 退格键
self.driver.press_keycode(67)

我前几天也遇到了,原因是输入法干扰造成的,解决办法是:
capabilities.setCapability("unicodeKeyboard",true);
把键盘锁住,副作用是想手动输入得去设置里面把键盘解锁了

用 appium 输入法,万事大吉

simple 回复

//设置启动参数
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);
capabilities.setCapability("noSign", true);
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "M95QACP4KTFE5");
capabilities.setCapability("platformVersions", "5.1");

//capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.mm.epass.sample");
capabilities.setCapability("appActivity", "com.mm.epass.sample.MainActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
capabilities.setCapability("noReset", true);
capabilities.setCapability("sessionOverride", true);
// 设置隐式等待超时时间
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Thread.sleep(10000);

不行呀,试了好几次

试了好多种办法,还是不行,求助社区
设置参数

capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);

WebElement loginUsr = driver.findElement(By.id(loginId));
        loginUsr.click();
        loginUsr.clear();
        loginUsr.sendKeys("testt");

WebElement loginPwd = driver.findElement(By.id(loginPwdId));
        loginPwd.click();
        loginPwd.clear();
        loginPwd.sendKeys("test123");
[HTTP] --> POST /wd/hub/session {"capabilities":[{"desiredCapabilities":{"appPackage":"com.mm.epass.sample","appActivity":"com.mm.epass.sample.MainActivity","platformVersions":"5.1","noSign":true,"browserName":"","unicodeKeyboard":true,"platformName":"Android","deviceName":"M95QACP4KTFE5","resetKeyboard":true}},{"requiredCapabilities":{}}],"desiredCapabilities":{"appPackage":"com.mm.epass.sample","appActivity":"com.mm.epass.sample.MainActivity","platformVersions":"5.1","noSign":true,"browserName":"","unicodeKeyboard":true,"platformName":"Android","deviceName":"M95QACP4KTFE5","resetKeyboard":true},"requiredCapabilities":{}}

["-P",5037,"-s","9184b4a3","shell","input","keyevent","67","112","67","112","67","112","67","112","67","112"]
[debug] [MJSONWP] Responding to client with driver.clear() result: null
[HTTP] <-- POST /wd/hub/session/9eb24dd7-1898-42f3-a08d-57623c90038b/element/3/clear 200 4065 ms - 76 
[HTTP] --> POST /wd/hub/session/9eb24dd7-1898-42f3-a08d-57623c90038b/element/3/value {"id":"3","value":["testt"]}
[debug] [MJSONWP] Calling AppiumDriver.setValue() with args: [["testt"],"3","9eb24dd7-1898-42f3-a08d-57623c90038b"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:setText","params":{"elementId":"3","text":"testt","replace":false,"unicodeKeyboard":true}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"3","text":"testt","replace":false,"unicodeKeyboard":true}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: setText
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using element passed in: 3
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Attempting to clear using UiObject.clearText().
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Text remains after clearing, but it appears to be hint text.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Text not cleared. Assuming remainder is hint text.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Sending plain text to element: testt
[HTTP] <-- POST /wd/hub/session/9eb24dd7-1898-42f3-a08d-57623c90038b/element/3/value - - ms - - 
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.setValue() result: true
[HTTP] --> POST /wd/hub/session/9eb24dd7-1898-42f3-a08d-57623c90038b/element/3/value {"id":"3","value":["testt"]}
[debug] [MJSONWP] Calling AppiumDriver.setValue() with args: [["testt"],"3","9eb24dd7-1898-42f3-a08d-57623c90038b"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:setText","params":{"elementId":"3","text":"testt","replace":false,"unicodeKeyboard":true}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"3","text":"testt","replace":false,"unicodeKeyboard":true}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: setText
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using element passed in: 3
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Attempting to clear using UiObject.clearText().
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Clearing text not successful. Attempting to clear by selecting all and deleting.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Clearing text not successful. Attempting to clear by sending delete keys.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Text remains after clearing, but it appears to be hint text.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Text not cleared. Assuming remainder is hint text.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Sending plain text to element: testt
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.setValue() result: true
[HTTP] <-- POST /wd/hub/session/9eb24dd7-1898-42f3-a08d-57623c90038b/element/3/value 200 16864 ms - 76 
[HTTP] --> POST /wd/hub/session/9eb24dd7-1898-42f3-a08d-57623c90038b/element {"using":"id","value":"com.meituan.epassport.sample:id/biz_tv_password"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","com.meituan.epassport.sample:id/biz_tv_password","9eb24dd7-1898-42f3-a08d-57623c90038b"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 20000 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.meituan.epassport.sample:id/biz_tv_password","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.meituan.epassport.sample:id/biz_tv_password","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.meituan.epassport.sample:id/biz_tv_password' using 'ID' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.meituan.epassport.sample:id/biz_tv_password]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"4"}}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"4"}
[HTTP] <-- POST /wd/hub/session/9eb24dd7-1898-42f3-a08d-57623c90038b/element 200 593 ms - 87 
[HTTP] --> POST /wd/hub/session/9eb24dd7-1898-42f3-a08d-57623c90038b/element/4/clear {"id":"4"}
[debug] [MJSONWP] Calling AppiumDriver.clear() with args: ["4","9eb24dd7-1898-42f3-a08d-57623c90038b"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:getText","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getText
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":""}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"4"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [ADB] Clearing up to 100 characters
[debug] [ADB] Getting connected devices...
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册