Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

driver.findElements(By.xpath(...)) returns incorrect result when testing Android #100

Copy link
Copy link
@esimeonov

Description

@esimeonov
Issue body actions

Hi guys,

I have an Android test, where I am using

List<MobileElement> elements = driver.findElements(By.xpath("//android.widget.Button[@text='Add']")); 

Surprisingly the number of returned elements is 2 instead of 1. I have only 1 "Add" button. Inspecting the list, I found out that the other entry was a button named "Pick". Tried the same with other unique controls and the number of the found elements was always incorrect. In addition the resulting list always contains arbitrary elements having nothing to do with the passed XPath selector.

This is what Appium dumps in the console when I execute the statement above:

info: --> POST /wd/hub/session/62384a2c-dadd-452f-8f41-975f36276e41/elements {"using":"xpath","value":"//android.widget.Button[@text='Add']"}
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//android.widget.Button[@text='Add']","context":"","multiple":true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.Button[@text='Add']","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 //android.widget.Button[@text='Add'] using XPATH with the contextId: multiple: true
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.Button, INSTANCE=1]
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (1)
info: [debug] [BOOTSTRAP] [debug] Element[] is null: (2)
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[{"ELEMENT":"28"},{"ELEMENT":"29"}],"status":0}
info: [debug] Responding to client with success: {"status":0,"value":[{"ELEMENT":"28"},{"ELEMENT":"29"}],"sessionId":"62384a2c-dadd-452f-8f41-975f36276e41"}
info: <-- POST /wd/hub/session/62384a2c-dadd-452f-8f41-975f36276e41/elements 200 173.614 ms - 107 {"status":0,"value":[{"ELEMENT":"28"},{"ELEMENT":"29"}],"sessionId":"62384a2c-dadd-452f-8f41-975f36276e41"}

Using the statement below I always ended up with a correct result list, which made me think that there is something wrong only with the XPath search.

List<MobileElement> elements = driver.findElements(By.name("Add")); 

Environment: Mac OS, Android API level 19 (tested with the UIAutomator (Appium) automation engine), Appium 1.2.2, Appium Java Client 1.6.1.

Is there anything that I could do, so the driver.findElements(By.xpath(...)) method would work correctly?

Thank you in advance! 🙇

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.