{"action":"created","issue":{"url":"https://api.github.com/repos/appium/appium/issues/5830","labels_url":"https://api.github.com/repos/appium/appium/issues/5830/labels{/name}","comments_url":"https://api.github.com/repos/appium/appium/issues/5830/comments","events_url":"https://api.github.com/repos/appium/appium/issues/5830/events","html_url":"https://github.com/appium/appium/issues/5830","id":116810322,"number":5830,"title":"\"wait-until-page-is-loaded\" issue with \"dontStopAppOnReset\":true and Android","user":{"login":"yahman72","id":8724383,"avatar_url":"https://avatars.githubusercontent.com/u/8724383?v=3","gravatar_id":"","url":"https://api.github.com/users/yahman72","html_url":"https://github.com/yahman72","followers_url":"https://api.github.com/users/yahman72/followers","following_url":"https://api.github.com/users/yahman72/following{/other_user}","gists_url":"https://api.github.com/users/yahman72/gists{/gist_id}","starred_url":"https://api.github.com/users/yahman72/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahman72/subscriptions","organizations_url":"https://api.github.com/users/yahman72/orgs","repos_url":"https://api.github.com/users/yahman72/repos","events_url":"https://api.github.com/users/yahman72/events{/privacy}","received_events_url":"https://api.github.com/users/yahman72/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/appium/appium/labels/NeedsTriage","name":"NeedsTriage","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-13T17:14:30Z","updated_at":"2015-12-01T13:34:01Z","closed_at":null,"body":"I'm experiencing some weird behaviour with my App (Android 5.0 & Samsung S5) when running it with \"dontStopAppOnReset\":true with Appium 1.4.13.1\r\n\r\nAfter opening the session, I want to click an element containing text \"Settings\", but sometimes this clicks a wrong element. Especially when the app is already open and I just reactivate it (i.e. \"dontStopAppOnReset\":true).\r\n\r\nSo I modified my code to first search for the element containing text \"Settings\" and the click on it (i.e. search+click) --> appium seems to return different elements for the two seaches (not 100% sure if I understand the logs correctly):\r\n1st search returns the 2nd element which is wrong i.e. \r\n  `Using: UiSelector[CLASS=android.widget.TextView, INSTANCE=2]`\r\n2nd search returns the 4th element which is correct i.e. \r\n  `Using: UiSelector[CLASS=android.widget.TextView, INSTANCE=4]` \r\n\r\nObviously the UI is not yet ready when the first search is done. Any ideas how to prevent this?\r\n\r\nI could of course always wait a few seconds before clicking the element but that'll be pretty ugly. \r\nAs a matter of fact I have experienced the same with other apps (and with \"dontStopAppOnReset\":false) but since the problem was more or less impossible to reproduce I have just ignored it.\r\n\r\nAppium doesn't seem to use the `-W` flag when launching the app, which - according to http://developer.android.com/tools/help/shell.html (`-W: Wait for launch to complete.`) - might be a simple solution to the problem, \r\n\r\n\r\nFull logs:\r\n<pre>\r\n--\r\n2015-11-13 17:46:05:521 - info: --> POST /wd/hub/session/110c0b41-8aca-4d9e-a56b-fd8872e83089/elements {\"using\":\"xpath\",\"sessionId\":\"110c0b41-8aca-4d9e-a56b-fd8872e83089\",\"value\":\"//*[contains(@text,'Settings')]\"}\r\n2015-11-13 17:46:05:521 - info: [debug] Waiting up to 0ms for condition\r\n2015-11-13 17:46:05:521 - info: [debug] Pushing command to appium work queue: [\"find\",{\"strategy\":\"xpath\",\"selector\":\"//*[contains(@text,'Settings')]\",\"context\":\"\",\"multiple\":true}]\r\n2015-11-13 17:46:05:521 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {\"cmd\":\"action\",\"action\":\"find\",\"params\":{\"strategy\":\"xpath\",\"selector\":\"//*[contains(@text,'Settings')]\",\"context\":\"\",\"multiple\":true}}\r\n2015-11-13 17:46:05:521 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION\r\n2015-11-13 17:46:05:521 - info: [debug] [BOOTSTRAP] [debug] Got command action: find\r\n2015-11-13 17:46:05:536 - info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(@text,'Settings')] using XPATH with the contextId:  multiple: true\r\n2015-11-13 17:46:05:583 - info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.TextView, INSTANCE=2]\r\n2015-11-13 17:46:05:583 - info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[CLASS=android.widget.TextView, INSTANCE=2]\r\n2015-11-13 17:46:05:599 - info: [debug] [BOOTSTRAP] [debug] Selector ends with instance.\r\n2015-11-13 17:46:05:670 - info: [debug] [BOOTSTRAP] [debug] Returning result: {\"status\":0,\"value\":[{\"ELEMENT\":\"1\"}]}\r\n2015-11-13 17:46:05:672 - info: [debug] Responding to client with success: {\"status\":0,\"value\":[{\"ELEMENT\":\"1\"}],\"sessionId\":\"110c0b41-8aca-4d9e-a56b-fd8872e83089\"}\r\n--\r\n2015-11-13 17:46:05:698 - info: --> POST /wd/hub/session/110c0b41-8aca-4d9e-a56b-fd8872e83089/elements {\"using\":\"xpath\",\"sessionId\":\"110c0b41-8aca-4d9e-a56b-fd8872e83089\",\"value\":\"//*[contains(@text,'Settings')]\"}\r\n2015-11-13 17:46:05:698 - info: [debug] Waiting up to 0ms for condition\r\n2015-11-13 17:46:05:699 - info: [debug] Pushing command to appium work queue: [\"find\",{\"strategy\":\"xpath\",\"selector\":\"//*[contains(@text,'Settings')]\",\"context\":\"\",\"multiple\":true}]\r\n2015-11-13 17:46:05:708 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {\"cmd\":\"action\",\"action\":\"find\",\"params\":{\"strategy\":\"xpath\",\"selector\":\"//*[contains(@text,'Settings')]\",\"context\":\"\",\"multiple\":true}}\r\n2015-11-13 17:46:05:717 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION\r\n2015-11-13 17:46:05:717 - info: [debug] [BOOTSTRAP] [debug] Got command action: find\r\n2015-11-13 17:46:05:718 - info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(@text,'Settings')] using XPATH with the contextId:  multiple: true\r\n2015-11-13 17:46:05:980 - info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.TextView, INSTANCE=4]\r\n2015-11-13 17:46:05:982 - info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[CLASS=android.widget.TextView, INSTANCE=4]\r\n2015-11-13 17:46:05:983 - info: [debug] [BOOTSTRAP] [debug] Selector ends with instance.\r\n2015-11-13 17:46:07:431 - info: [debug] [BOOTSTRAP] [debug] Returning result: {\"status\":0,\"value\":[{\"ELEMENT\":\"2\"}]}\r\n2015-11-13 17:46:07:432 - info: [debug] Responding to client with success: {\"status\":0,\"value\":[{\"ELEMENT\":\"2\"}],\"sessionId\":\"110c0b41-8aca-4d9e-a56b-fd8872e83089\"}\r\n--\r\n</pre>\r\n\r\nWhen app is not yet running things go fine i.e. both searches return the same element:\r\n<pre>\r\n--\r\n2015-11-13 17:45:50:973 - info: --> POST /wd/hub/session/6115f106-91c9-4af4-a2e3-1eebf2d0f79b/elements {\"using\":\"xpath\",\"sessionId\":\"6115f106-91c9-4af4-a2e3-1eebf2d0f79b\",\"value\":\"//*[contains(@text,'Settings')]\"}\r\n2015-11-13 17:45:50:974 - info: [debug] Waiting up to 0ms for condition\r\n2015-11-13 17:45:50:979 - info: [debug] Pushing command to appium work queue: [\"find\",{\"strategy\":\"xpath\",\"selector\":\"//*[contains(@text,'Settings')]\",\"context\":\"\",\"multiple\":true}]\r\n2015-11-13 17:45:50:998 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {\"cmd\":\"action\",\"action\":\"find\",\"params\":{\"strategy\":\"xpath\",\"selector\":\"//*[contains(@text,'Settings')]\",\"context\":\"\",\"multiple\":true}}\r\n2015-11-13 17:45:50:999 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION\r\n2015-11-13 17:45:50:999 - info: [debug] [BOOTSTRAP] [debug] Got command action: find\r\n2015-11-13 17:45:51:000 - info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(@text,'Settings')] using XPATH with the contextId:  multiple: true\r\n2015-11-13 17:45:53:734 - info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.TextView, INSTANCE=4]\r\n2015-11-13 17:45:53:735 - info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[CLASS=android.widget.TextView, INSTANCE=4]\r\n2015-11-13 17:45:53:736 - info: [debug] [BOOTSTRAP] [debug] Selector ends with instance.\r\n2015-11-13 17:45:53:955 - info: [debug] [BOOTSTRAP] [debug] Returning result: {\"status\":0,\"value\":[{\"ELEMENT\":\"1\"}]}\r\n2015-11-13 17:45:53:956 - info: [debug] Responding to client with success: {\"status\":0,\"value\":[{\"ELEMENT\":\"1\"}],\"sessionId\":\"6115f106-91c9-4af4-a2e3-1eebf2d0f79b\"}\r\n--\r\n2015-11-13 17:45:53:982 - info: --> POST /wd/hub/session/6115f106-91c9-4af4-a2e3-1eebf2d0f79b/elements {\"using\":\"xpath\",\"sessionId\":\"6115f106-91c9-4af4-a2e3-1eebf2d0f79b\",\"value\":\"//*[contains(@text,'Settings')]\"}\r\n2015-11-13 17:45:53:987 - info: [debug] Waiting up to 0ms for condition\r\n2015-11-13 17:45:53:999 - info: [debug] Pushing command to appium work queue: [\"find\",{\"strategy\":\"xpath\",\"selector\":\"//*[contains(@text,'Settings')]\",\"context\":\"\",\"multiple\":true}]\r\n2015-11-13 17:45:54:002 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {\"cmd\":\"action\",\"action\":\"find\",\"params\":{\"strategy\":\"xpath\",\"selector\":\"//*[contains(@text,'Settings')]\",\"context\":\"\",\"multiple\":true}}\r\n2015-11-13 17:45:54:002 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION\r\n2015-11-13 17:45:54:003 - info: [debug] [BOOTSTRAP] [debug] Got command action: find\r\n2015-11-13 17:45:54:004 - info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(@text,'Settings')] using XPATH with the contextId:  multiple: true\r\n2015-11-13 17:45:54:081 - info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.TextView, INSTANCE=4]\r\n2015-11-13 17:45:54:082 - info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[CLASS=android.widget.TextView, INSTANCE=4]\r\n2015-11-13 17:45:54:082 - info: [debug] [BOOTSTRAP] [debug] Selector ends with instance.\r\n2015-11-13 17:45:54:105 - info: [debug] [BOOTSTRAP] [debug] Returning result: {\"status\":0,\"value\":[{\"ELEMENT\":\"2\"}]}\r\n2015-11-13 17:45:54:105 - info: [debug] Responding to client with success: {\"status\":0,\"value\":[{\"ELEMENT\":\"2\"}],\"sessionId\":\"6115f106-91c9-4af4-a2e3-1eebf2d0f79b\"}\r\n--\r\n</pre>\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/appium/appium/issues/comments/160970260","html_url":"https://github.com/appium/appium/issues/5830#issuecomment-160970260","issue_url":"https://api.github.com/repos/appium/appium/issues/5830","id":160970260,"user":{"login":"yahman72","id":8724383,"avatar_url":"https://avatars.githubusercontent.com/u/8724383?v=3","gravatar_id":"","url":"https://api.github.com/users/yahman72","html_url":"https://github.com/yahman72","followers_url":"https://api.github.com/users/yahman72/followers","following_url":"https://api.github.com/users/yahman72/following{/other_user}","gists_url":"https://api.github.com/users/yahman72/gists{/gist_id}","starred_url":"https://api.github.com/users/yahman72/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yahman72/subscriptions","organizations_url":"https://api.github.com/users/yahman72/orgs","repos_url":"https://api.github.com/users/yahman72/repos","events_url":"https://api.github.com/users/yahman72/events{/privacy}","received_events_url":"https://api.github.com/users/yahman72/received_events","type":"User","site_admin":false},"created_at":"2015-12-01T13:34:01Z","updated_at":"2015-12-01T13:34:01Z","body":"Any comments on this?"}}