{"action":"created","issue":{"url":"https://api.github.com/repos/appium/java-client/issues/226","labels_url":"https://api.github.com/repos/appium/java-client/issues/226/labels{/name}","comments_url":"https://api.github.com/repos/appium/java-client/issues/226/comments","events_url":"https://api.github.com/repos/appium/java-client/issues/226/events","html_url":"https://github.com/appium/java-client/issues/226","id":99646504,"number":226,"title":"UiScrollable Within A Context - Scrolling First Element","user":{"login":"anders-g-hansen","id":11392648,"avatar_url":"https://avatars.githubusercontent.com/u/11392648?v=3","gravatar_id":"","url":"https://api.github.com/users/anders-g-hansen","html_url":"https://github.com/anders-g-hansen","followers_url":"https://api.github.com/users/anders-g-hansen/followers","following_url":"https://api.github.com/users/anders-g-hansen/following{/other_user}","gists_url":"https://api.github.com/users/anders-g-hansen/gists{/gist_id}","starred_url":"https://api.github.com/users/anders-g-hansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anders-g-hansen/subscriptions","organizations_url":"https://api.github.com/users/anders-g-hansen/orgs","repos_url":"https://api.github.com/users/anders-g-hansen/repos","events_url":"https://api.github.com/users/anders-g-hansen/events{/privacy}","received_events_url":"https://api.github.com/users/anders-g-hansen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-07T13:25:10Z","updated_at":"2015-08-29T05:59:22Z","closed_at":null,"body":"Sending a UiScrollable command to a page that contains multiple scrollable elements always appears to act upon the first scrollable element even when a context is provided.\r\n\r\nHere is an example using test I plugged into the java-client AndroidUIAutomatorTest class to demonstrate the issue.  Note, the test navigates to a page in the test app which has multiple scrollables.  When it attempts to scroll to find an element it scrolls the wrong scrollable (first on the page) rather than the element in the provided context.\r\n\r\n\t  @Test\r\n\t  public void scrollBars() {\r\n\t\tdriver.scrollToExact(\"Views\").click();\r\n\t\tdriver.scrollToExact(\"ScrollBars\").click();\r\n\t\tdriver.scrollToExact(\"3. Style\").click();\r\n\r\n\t\t// find the middle ScrollView (second one since we're 0 based index)\r\n\t\tAndroidElement element = driver.findElementByAndroidUIAutomator(\"new UiSelector().className(android.widget.ScrollView).index(1)\");\r\n\t\tassertTrue(element.isDisplayed());\r\n\r\n\t\tAndroidElement found;\r\n\r\n\t\t// use a UiScrollable selector with something we know will be found within the context of the middle scrollview and print the text to ensure it works\r\n\t\tfound = element.findElementByAndroidUIAutomator(\"new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(className(android.widget.TextView))\");\r\n\t\tassertTrue(found.isDisplayed());\r\n\t\tSystem.out.println(\"text: \" + found.getText());\r\n\r\n\t\t// use a UiScrollable selector with something ew know will NOT be found to see if it will properly scroll to find it, note it is scrolling the first Scrollable on the page\r\n\t\t// not the one with the \"element\" context\r\n\t\tfound = element.findElementByAndroidUIAutomator(\"new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(resourceId(\\\"notFoundId\\\"))\");\r\n\t\tassertTrue(found.isDisplayed());\r\n\t\tSystem.out.println(\"text: \" + found.getText());\r\n\r\n\t  }\r\n\r\nHere are the appium logs for the above test run.\r\n\r\nThe first log provided is from the first find within the context (4 from the log).  This call works as expected.\r\n\r\n\t\tinfo: --> POST /wd/hub/session/84c164f6-fc7c-433f-ac46-7cae26739c05/element/4/element {\"id\":\"4\",\"using\":\"-android uiautomator\",\"value\":\"new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(className(android.widget.TextView))\"}\r\n\t\tinfo: [debug] Waiting up to 0ms for condition\r\n\t\tinfo: [debug] Pushing command to appium work queue: [\"find\",{\"strategy\":\"-android uiautomator\",\"selector\":\"new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(className(android.widget.TextView))\",\"context\":\"4\",\"multiple\":false}]\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Got data from client: {\"cmd\":\"action\",\"action\":\"find\",\"params\":{\"strategy\":\"-android uiautomator\",\"selector\":\"new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(className(android.widget.TextView))\",\"context\":\"4\",\"multiple\":false}}\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Got command of type ACTION\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Got command action: find\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Finding new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(className(android.widget.TextView)) using ANDROID_UIAUTOMATOR with the contextId: 4 multiple: false\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Parsing scrollable: new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(className(android.widget.TextView))\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: boolean arg: true\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiScrollable invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException args: className(android.widget.TextView),\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiScrollable coerce type: class com.android.uiautomator.core.UiObject arg: className(android.widget.TextView)\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: java.lang.Class<T> arg: android.widget.TextView\r\n\t\tinfo: [debug] [UIAUTOMATOR STDOUT] referenceTable GDEF length=778 1\r\n\t\tinfo: [debug] [UIAUTOMATOR STDOUT] referenceTable GSUB length=6388 1\r\n\t\tinfo: [debug] [UIAUTOMATOR STDOUT] referenceTable GPOS length=66796 1\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: class java.lang.String arg: android.widget.TextView\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Method name: scrollIntoView\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Setting uiObject for scrollIntoView\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.TextView]\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Returning result: {\"status\":0,\"value\":{\"ELEMENT\":\"5\"}}\r\n\t\tinfo: [debug] Responding to client with success: {\"status\":0,\"value\":{\"ELEMENT\":\"5\"},\"sessionId\":\"84c164f6-fc7c-433f-ac46-7cae26739c05\"}\r\n\t\tinfo: <-- POST /wd/hub/session/84c164f6-fc7c-433f-ac46-7cae26739c05/element/4/element 200 109.181 ms - 87 {\"status\":0,\"value\":{\"ELEMENT\":\"5\"},\"sessionId\":\"84c164f6-fc7c-433f-ac46-7cae26739c05\"}\r\n\r\nThis log is from the call which results in scrolling the wrong scrollable.  Though the context of \"4\" was provided, it ends up scrolling the first scrollable on the page NOT the one within the provided context.\r\n\r\n\t\tinfo: --> POST /wd/hub/session/f709bb83-1ef2-41c9-a874-bbb6eeb9b471/element/4/element {\"id\":\"4\",\"using\":\"-android uiautomator\",\"value\":\"new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(resourceId(\\\"notFoundId\\\"))\"}\r\n\t\tinfo: [debug] Waiting up to 0ms for condition\r\n\t\tinfo: [debug] Pushing command to appium work queue: [\"find\",{\"strategy\":\"-android uiautomator\",\"selector\":\"new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(resourceId(\\\"notFoundId\\\"))\",\"context\":\"4\",\"multiple\":false}]\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Got data from client: {\"cmd\":\"action\",\"action\":\"find\",\"params\":{\"strategy\":\"-android uiautomator\",\"selector\":\"new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(resourceId(\\\"notFoundId\\\"))\",\"context\":\"4\",\"multiple\":false}}\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Got command of type ACTION\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Got command action: find\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Finding new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(resourceId(\"notFoundId\")) using ANDROID_UIAUTOMATOR with the contextId: 4 multiple: false\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Parsing scrollable: new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(resourceId(\"notFoundId\"))\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: boolean arg: true\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiScrollable invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException args: resourceId(\"notFoundId\"),\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiScrollable coerce type: class com.android.uiautomator.core.UiObject arg: resourceId(\"notFoundId\")\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: class java.lang.String arg: \"notFoundId\"\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Method name: scrollIntoView\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Setting uiObject for scrollIntoView\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException with: com.android.uiautomator.core.UiObject@f374fae\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Invoke complete.\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=notFoundId]\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Failed to locate element. Clearing Accessibility cache and retrying.\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Finding new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(resourceId(\"notFoundId\")) using ANDROID_UIAUTOMATOR with the contextId: 4 multiple: false\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Parsing scrollable: new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(resourceId(\"notFoundId\"))\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: boolean arg: true\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiScrollable invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException args: resourceId(\"notFoundId\"),\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiScrollable coerce type: class com.android.uiautomator.core.UiObject arg: resourceId(\"notFoundId\")\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: class java.lang.String arg: \"notFoundId\"\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Method name: scrollIntoView\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Setting uiObject for scrollIntoView\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Invoking method: public boolean com.android.uiautomator.core.UiScrollable.scrollIntoView(com.android.uiautomator.core.UiObject) throws com.android.uiautomator.core.UiObjectNotFoundException with: com.android.uiautomator.core.UiObject@2368214f\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Invoke complete.\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=notFoundId]\r\n\t\tinfo: [debug] [BOOTSTRAP] [debug] Returning result: {\"status\":7,\"value\":\"No element found\"}\r\n\t\tinfo: [debug] Condition unmet after 15967ms. Timing out.\r\n\t\tinfo: [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\":\"No element found\"},\"sessionId\":\"f709bb83-1ef2-41c9-a874-bbb6eeb9b471\"}\r\n\t\tinfo: <-- POST /wd/hub/session/f709bb83-1ef2-41c9-a874-bbb6eeb9b471/element/4/element 500 15971.919 ms - 195\r\n\t\tinfo: --> DELETE /wd/hub/session/f709bb83-1ef2-41c9-a874-bbb6eeb9b471 {}\r\n\r\nI suspect it is losing the context when it fails to find the element and we see this line in the log:\r\n\r\n> info: [debug] [BOOTSTRAP] [debug] Failed to locate element. Clearing Accessibility cache and retrying.\r\n "},"comment":{"url":"https://api.github.com/repos/appium/java-client/issues/comments/135945625","html_url":"https://github.com/appium/java-client/issues/226#issuecomment-135945625","issue_url":"https://api.github.com/repos/appium/java-client/issues/226","id":135945625,"user":{"login":"aniket-21","id":4035405,"avatar_url":"https://avatars.githubusercontent.com/u/4035405?v=3","gravatar_id":"","url":"https://api.github.com/users/aniket-21","html_url":"https://github.com/aniket-21","followers_url":"https://api.github.com/users/aniket-21/followers","following_url":"https://api.github.com/users/aniket-21/following{/other_user}","gists_url":"https://api.github.com/users/aniket-21/gists{/gist_id}","starred_url":"https://api.github.com/users/aniket-21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aniket-21/subscriptions","organizations_url":"https://api.github.com/users/aniket-21/orgs","repos_url":"https://api.github.com/users/aniket-21/repos","events_url":"https://api.github.com/users/aniket-21/events{/privacy}","received_events_url":"https://api.github.com/users/aniket-21/received_events","type":"User","site_admin":false},"created_at":"2015-08-29T05:59:22Z","updated_at":"2015-08-29T05:59:22Z","body":"I could replicate the issue but its really weird cos I could see context Id being retained and its the same parent element on which getChild method being called. Parent object is persistent in Element hash. Still wondering what is causing it to search in 1st scrollable instead of 2nd.\r\nWill try to look into again sometime later today"}}