[Android] element.findElements() returns wrong result
See original GitHub issueHi,
I’m using Appium@1.3.4 and Android 4.4.4.
Our app has a page that contains a list of TV channels. Each channel MAY have a little LIVE icon. This is how it looks on the UI :
And this is the UI hierarchy for the channel w/o LIVE icon :
and with LIVE icon :
At first I’m finding the channel element using :
WebElement firstChannel = driver.findElements(By.id("com.company.app:id/visibleChannel")).get(0);
Then I’m looking for child LIVE element under the channel. And the problem is that if the channel element does not contain LIVE icon, appium anyway returns some element. I found out that it is the nearest available LIVE icon from the nearest channel in the UI tree.
So for that case the following code returns 1
:
firstChannel.findElements(By.id("com.company.app:id/listing_live_btn")).size();
And here’s corresponding appium log :
info: --> POST /wd/hub/session/e52db23d-bd9e-470f-98d7-1358a4f94afc/elements {"using":"id","value":"com.company.app:id/visibleChannel"}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.company.app:id/visibleChannel","context":"","multiple":true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.company.app:id/visibleChannel","context":"","multiple":true}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding com.company.app:id/visibleChannel using ID with the contextId: multiple: true
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (1)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=1, RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (2)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=2, RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (3)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=3, RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (4)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=4, RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (5)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=5, RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (6)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=6, RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (7)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=7, RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (8)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=8, RESOURCE_ID=com.company.app:id/visibleChannel]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[{"ELEMENT":"195"},{"ELEMENT":"196"},{"ELEMENT":"197"},{"ELEMENT":"198"},{"ELEMENT":"199"},{"ELEMENT":"200"},{"ELEMENT":"201"},{"ELEMENT":"202"}],"status":0}
info: [debug] Responding to client with success: {"status":0,"value":[{"ELEMENT":"195"},{"ELEMENT":"196"},{"ELEMENT":"197"},{"ELEMENT":"198"},{"ELEMENT":"199"},{"ELEMENT":"200"},{"ELEMENT":"201"},{"ELEMENT":"202"}],"sessionId":"e52db23d-bd9e-470f-98d7-1358a4f94afc"}
info: <-- POST /wd/hub/session/e52db23d-bd9e-470f-98d7-1358a4f94afc/elements 200 139.860 ms - 217 {"status":0,"value":[{"ELEMENT":"195"},{"ELEMENT":"196"},{"ELEMENT":"197"},{"ELEMENT":"198"},{"ELEMENT":"199"},{"ELEMENT":"200"},{"ELEMENT":"201"},{"ELEMENT":"202"}],"sessionId":"e52db23d-bd9e-470f-98d7-1358a4f94afc"}
info: --> POST /wd/hub/session/e52db23d-bd9e-470f-98d7-1358a4f94afc/element/195/elements {"id":"195","using":"id","value":"com.company.app:id/listing_live_btn"}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.company.app:id/listing_live_btn","context":"195","multiple":true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.company.app:id/listing_live_btn","context":"195","multiple":true}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding com.company.app:id/listing_live_btn using ID with the contextId: 195 multiple: true
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=com.company.app:id/listing_live_btn]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[RESOURCE_ID=com.company.app:id/listing_live_btn]
info: [debug] [BOOTSTRAP] [debug] Element[195] is 195, counter: 0
info: [debug] [BOOTSTRAP] [debug] Element[195] is 195, counter: 1
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[{"ELEMENT":"203"}],"status":0}
info: [debug] Responding to client with success: {"status":0,"value":[{"ELEMENT":"203"}],"sessionId":"e52db23d-bd9e-470f-98d7-1358a4f94afc"}
info: <-- POST /wd/hub/session/e52db23d-bd9e-470f-98d7-1358a4f94afc/element/195/elements 200 37.645 ms - 91 {"status":0,"value":[{"ELEMENT":"203"}],"sessionId":"e52db23d-bd9e-470f-98d7-1358a4f94afc"}
Interesting thing is that if I will use Xpath then corresponding code will return 0
as expected :
driver.findElementsByXPath("//*[@resource-id='com.company.app:id/visibleChannel'][1]//*[@resource-id='com.company.app:id/listing_live_btn']").size()
Also log for that case :
info: --> POST /wd/hub/session/e52db23d-bd9e-470f-98d7-1358a4f94afc/elements {"using":"xpath","value":"//*[@resource-id='com.company.app:id/visibleChannel'][1]//*[@resource-id='com.company.app:id/listing_live_btn']"}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//*[@resource-id='com.company.app:id/visibleChannel'][1]//*[@resource-id='com.company.app:id/listing_live_btn']","context":"","multiple":true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[@resource-id='com.company.app:id/visibleChannel'][1]//*[@resource-id='com.company.app:id/listing_live_btn']","context":"","multiple":true}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding //*[@resource-id='com.company.app:id/visibleChannel'][1]//*[@resource-id='com.company.app:id/listing_live_btn'] using XPATH with the contextId: multiple: true
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[],"status":0}
info: [debug] Condition unmet after 85ms. Timing out.
info: [debug] Responding to client with success: {"status":0,"value":[],"sessionId":"e52db23d-bd9e-470f-98d7-1358a4f94afc"}
info: <-- POST /wd/hub/session/e52db23d-bd9e-470f-98d7-1358a4f94afc/elements 200 90.834 ms - 74 {"status":0,"value":[],"sessionId":"e52db23d-bd9e-470f-98d7-1358a4f94afc"}
Issue Analytics
- State:
- Created 9 years ago
- Comments:9 (1 by maintainers)
Top GitHub Comments
Ok, here’s how it could be done:
findElements()
and use XPath you will see other result - as expected:This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.