Cannot find element

Using appium inspector i created the command:
driver.FindElementByXPath("//android.widget.ImageView[@instance = 2]").Click();

But appium cannot find it.I have triple checked and the issue persists.I have given the log below.

Calling AppiumDriver.findElement() with args: [“xpath”,"//android.widget.ImageView[@instance = 2]",“568bee9c-fba9-404c-aa29-876a690c3411”]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:"//android.widget.ImageView[@instance = 2]",“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:"//android.widget.ImageView[@instance = 2]",“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘//android.widget.ImageView[@instance = 2]’ using ‘XPATH’ with the contextId: ‘’ multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘//android.widget.ImageView[@instance = 2]’ using ‘XPATH’ with the contextId: ‘’ multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:7,“value”:“No element found”}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[MJSONWP] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[MJSONWP] at AndroidDriver.callee$0$0$ (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11)
[MJSONWP] at tryCatch (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
[MJSONWP] at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
[MJSONWP] at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
[MJSONWP] at GeneratorFunctionPrototype.invoke (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[MJSONWP] at
[HTTP] <-- POST /wd/hub/session/568bee9c-fba9-404c-aa29-876a690c3411/element 500 104 ms - 164

But you can see it in Appium desktop? Can you post a screenshot?

I can see it. i put a screenshot of the inspector

Your element is not clickable. It’s attribute “clickable” is set to false.

I noticed that but when physical device is used the icon is taped to access the customer section

I know what you mean. Over this image, there are 3 viewGroups and I guess on of them must be clickable, and when you press on real device, on of these elements are being actually pressed. What you can do is (a little workaround):

WebElement yourImage = //get instance of your image
int pressY = yourImage.getLocation().getY() + (yourImage.getSize().getHeight() / 2)
int pressX = yourImage.getLocation().getX() + (yourImage.getSize().getWidth() / 2)

… this is how you get X and Y coordinates. Then make a custom tap by using TouchAction like this:

new TouchAction(driver).press(PointOption.point(pressX, pressY)).waitAction(WaitOptions.waitOptions(ofMillis(400))).release().perform();

Note: I haven’t tested the code, you might need to modify it a bit. Just to get the point…

2 Likes

Is there a c# equivalent?I couldn’t find one

@MrZigaS thanks for the help.I directly referenced the view group and it worked:)

Great, I’m glad you found the solution :slight_smile:

@Nathan1 Hey Nathan, would it be possible for you to share the code you used to fix your issue? Specifically how you directly referenced the view group? I am also having a similar issue. Thanks!

So what happened was that the image icon was not click able but the container it was located in was. so what to do is using appium inspector find the container which the icon is located in is clickable .I dont think the code will help as each app has its own names but i still included it.Let me know if u need anything else.

driver.FindElementByXPath("//android.view.ViewGroup[@instance = ‘10’]").Click();

1 Like

@Nathan1 thanks for the clarification. In my case, according to appium inspector, the container holding the image was not clickable either. But I was able to work around it by creating a list of elements with the ImageView class attribute and then clicking on the desired image icon. Here is my code if anyone in the future is reading this and needs help:

// Java
List image = driver.findElementsByClassName(“android.widget.ImageView”);
image.get(index).click();

1 Like

Your welcome.Glad i could help:)

Hey like my clickable value is true and I tried the driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
MobileElement element = (MobileElement) driver.findElement(MobileBy.id(“com.ninjafocus.app:id/signinButton”));
element.click();
Buy it showing an error to me
Matched W3C error code ‘no such element’ to NoSuchElementError
[debug] [W3C (1814727d)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
[debug] [W3C (1814727d)] at AndroidUiautomator2Driver.findElOrEls (C:\Users\pooja\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11)
[debug] [W3C (1814727d)] at AndroidUiautomator2Driver.findElOrElsWithProcessing (C:\Users\pooja\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\find.js:33:12)
[debug] [W3C (1814727d)] at AndroidUiautomator2Driver.findElement (C:\Users\pooja\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\find.js:53:10)
[HTTP] <-- POST /wd/hub/session/1814727d-bb07-41c6-9898-d30b5588a356/element 404

Please help me for some solution