{"action":"closed","issue":{"url":"https://api.github.com/repos/appium/appium/issues/4177","labels_url":"https://api.github.com/repos/appium/appium/issues/4177/labels{/name}","comments_url":"https://api.github.com/repos/appium/appium/issues/4177/comments","events_url":"https://api.github.com/repos/appium/appium/issues/4177/events","html_url":"https://github.com/appium/appium/issues/4177","id":50193574,"number":4177,"title":"SendKeys on Android hinted TextViews switches the focus and influences neighbour controls","user":{"login":"danail-branekov","id":5657719,"avatar_url":"https://avatars.githubusercontent.com/u/5657719?v=3","gravatar_id":"","url":"https://api.github.com/users/danail-branekov","html_url":"https://github.com/danail-branekov","followers_url":"https://api.github.com/users/danail-branekov/followers","following_url":"https://api.github.com/users/danail-branekov/following{/other_user}","gists_url":"https://api.github.com/users/danail-branekov/gists{/gist_id}","starred_url":"https://api.github.com/users/danail-branekov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danail-branekov/subscriptions","organizations_url":"https://api.github.com/users/danail-branekov/orgs","repos_url":"https://api.github.com/users/danail-branekov/repos","events_url":"https://api.github.com/users/danail-branekov/events{/privacy}","received_events_url":"https://api.github.com/users/danail-branekov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/appium/appium/labels/Android","name":"Android","color":"ADFF2F"},{"url":"https://api.github.com/repos/appium/appium/labels/Bug","name":"Bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-11-26T15:43:04Z","updated_at":"2015-05-11T23:37:29Z","closed_at":"2015-05-11T23:37:29Z","body":"Hi,\r\n\r\nThis might be a duplicate to https://github.com/appium/appium/issues/3900 but the issue is closed so I am creating a new one as the fix does not seem to work properly. The issue itself is that on clearing a hinted Android text view the focus is switched to the neighbour control. There are applications (such as the EBay one) which validates things on focus lost and bring up alerts thus preventing from further interaction.\r\n\r\nI am using Appium Beta (Appium v1.3.4-beta1 (REV a242d62eb1a0002db12d7eaeaf4de2508ae3ce7a)) on OS X to automate the Ebay android application. The application itself is https://play.google.com/store/apps/details?id=com.ebay.mobile&hl=en and you can download the APK via third parties tools such as http://apps.evozi.com/apk-downloader/\r\n\r\nThe test:\r\n\r\n```java\r\n    @Test\r\n    public void test() {\r\n        delay();\r\n        final WebElement signInButton = driver.findElement(By.id(\"com.ebay.mobile:id/button_sign_in\"));\r\n        signInButton.click();\r\n        delay();\r\n\r\n        final WebElement userName = driver.findElement(By.id(\"com.ebay.mobile:id/sign_in_username_entry\"));\r\n        userName.sendKeys(\"sample user\");\r\n        delay();\r\n    }\r\n\r\n    private void delay() {\r\n        try {\r\n            Thread.sleep(3000);\r\n        } catch (InterruptedException e) {\r\n            throw new RuntimeException(e);\r\n        }\r\n    }\r\n```\r\n\r\nWhenever the test executes “sendKeys” Appium would try to clear the text field first. Upon clearing it would switch the focus to the next control (the password field) and the application would bring a popup saying that the user name is not correct.\r\n\r\nAs far as I can understand this behaviour is caused by io.appium.android.bootstrap.handler.Clear.hasHintText(AndroidElement, ReflectionUtils). Here is the implementation which checks for hinted text field:\r\n```java\r\n  private boolean hasHintText(AndroidElement el, final ReflectionUtils utils)\r\n      throws UiObjectNotFoundException, IllegalAccessException,\r\n        InvocationTargetException, NoSuchMethodException {\r\n………..\r\n    sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_BUTTON_THUMBR, 0);\r\n    sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_DEL, 0);\r\n    sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_BUTTON_THUMBL, 0);\r\n    sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_DEL, 0);\r\n    sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_FORWARD_DEL, 0);\r\n    return currText.equals(el.getText());\r\n  }\r\n```\r\n\r\nThe effect:\r\n* sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_BUTTON_THUMBR, 0); —> set focus on the password field\r\n* sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_DEL, 0); —> sends a delete key. At this point in time if the password field used to contain some text its first symbol is deleted, i.e. **sending keys has additional unwanted side effects**.\r\n* sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_BUTTON_THUMBL, 0); —> goes back to the username field. At this point of time the application validates the user/password and brings up a popup. Now the clear action is stuck and eventually fails with \r\n```\r\ninfo: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().\r\ninfo: [debug] [BOOTSTRAP] [debug] Updating class \"class com.android.uiautomator.core.UiDevice\" to enable field \"mUiAutomationBridge\"\r\ninfo: [debug] [BOOTSTRAP] [debug] Updating class \"class com.android.uiautomator.core.UiAutomatorBridge\" to enable field \"mInteractionController\"\r\ninfo: [debug] [BOOTSTRAP] [debug] Finding methods on class: class com.android.uiautomator.core.InteractionController\r\ninfo: [debug] [BOOTSTRAP] [debug] Returning result: {\"value\":\"UiSelector[INSTANCE=0, RESOURCE_ID=com.ebay.mobile:id\\/sign_in_username_entry]\",\"status\":7}\r\ninfo: [debug] Responding to client with error: {\"status\":7,\"value\":{\"message\":\"An element could not be located on the page using the given search parameters.\",\"origValue\":\"UiSelector[INSTANCE=0, RESOURCE_ID=com.ebay.mobile:id/sign_in_username_entry]\"},\"sessionId\":\"48829147-658a-4169-ac7a-2625c0ae0ae2\"}\r\ninfo: <-- POST /wd/hub/session/48829147-658a-4169-ac7a-2625c0ae0ae2/element/2/value 500 25214.478 ms - 256 \r\n```\r\n\r\nI have removed the first three method invocations so that the code looks like that:\r\n\r\n```java\r\n  private boolean hasHintText(AndroidElement el, final ReflectionUtils utils)\r\n      throws UiObjectNotFoundException, IllegalAccessException,\r\n        InvocationTargetException, NoSuchMethodException {\r\n    // to test if the remaining text is hint text, try sending a single\r\n    // delete key and testing if there is any change.\r\n    // ignore the off-chance that the delete silently fails and we get a false\r\n    // positive.\r\n    String currText = el.getText();\r\n\r\n    final Method sendKey = utils.getControllerMethod(\"sendKey\", int.class, int.class);\r\n    try {\r\n      if (!el.getBoolAttribute(\"focused\")) {\r\n        Logger.debug(\"Could not check for hint text because the element is not focused!\");\r\n        return false;\r\n      }\r\n    } catch(final Exception e) {\r\n      Logger.debug(\"Could not check for hint text: \" + e.getMessage());\r\n      return false;\r\n    }\r\n    sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_DEL, 0);\r\n    sendKey.invoke(utils.getController(), KeyEvent.KEYCODE_FORWARD_DEL, 0);\r\n    return currText.equals(el.getText());\r\n  }\r\n```\r\nThis implementation seems quite logical because if the text value did not change after pressing delete and forward delete then the text field is either hinted, or read-only. IMHO switching the focus to the previous/next controls is not really needed\r\n\r\nI tested my version of the Clear handler on hinted and non-hinted text fields and seems to be working properly. I would therefore propose to submit the change in Appium bootstrap\r\n\r\nRegards, Danail\r\n"}}