diff --git a/uiautomator2/__init__.py b/uiautomator2/__init__.py index 6ded921..747e6e4 100644 --- a/uiautomator2/__init__.py +++ b/uiautomator2/__init__.py @@ -587,7 +587,12 @@ def set_clipboard(self, text, label=None): def clear_text(self): """ clear input text """ - self.jsonrpc.clearInputText() + try: + # 这个问题基本不大 + # 不过考虑到u2.jar不一定升级成功了,所以还有留个兜底方案· + self.jsonrpc.clearInputText() + except: + self._clear_text_with_ime() def send_keys(self, text: str, clear: bool = False): """ @@ -599,8 +604,14 @@ def send_keys(self, text: str, clear: bool = False): """ if clear: self.clear_text() - self.clipboard = text - self.jsonrpc.pasteClipboard() + try: + # setClipboard的兼容性并不是特别好,但是这样做有个优点就是不用装输入法了。 + self.clipboard = text + if self.clipboard != text: + raise UiAutomationError("setClipboard failed") + self.jsonrpc.pasteClipboard() + except: + self._send_keys_with_ime(text) def keyevent(self, v): """ diff --git a/uiautomator2/_input.py b/uiautomator2/_input.py index a753077..54348e4 100644 --- a/uiautomator2/_input.py +++ b/uiautomator2/_input.py @@ -96,7 +96,6 @@ def _must_broadcast(self, action: str, extras: Dict[str, str] = {}): if result.code != BORADCAST_RESULT_OK: raise AdbBroadcastError(f"broadcast {action} failed: {result.data}") - @deprecated(reason="use send_keys instead") def _send_keys_with_ime(self, text: str): try: self.set_input_ime() @@ -140,7 +139,6 @@ def send_action(self, code: Union[str, int] = None): else: self._must_broadcast('ADB_KEYBOARD_SMART_ENTER') - @deprecated(reason="use clear_text() instead") def _clear_text_with_ime(self): """ clear text Raises: