The button can be found but no response after click or tap in Android

I met an issue that I can found the ‘Add’ button element but after click or tap, nothing happened.
I used the code below to locate the Add button and click it
‘… WebElement addbtn = this.driver.findElementByXPath(".//*[@content-desc=‘Add’]");
addbtn.click();
…’

Or

‘… WebElement addbtn = this.driver.findElementByXPath(".//*[@content-desc=‘Add’]");

TouchAction Action = new TouchAction((MobileDriver) driver);
Action.tap(addbtn).perform();

…’

Neither method worked after click Add, and in the Appium log it said,’
2016-11-30 09:40:09:900 - info: [debug] Pushing command to appium work queue: [“find”,{“strategy”:“xpath”,“selector”:".//[@content-desc=‘Add’]",“context”:"",“multiple”:false}]
2016-11-30 09:40:09:914 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:".//
[@content-desc=‘Add’]",“context”:"",“multiple”:false}}
2016-11-30 09:40:09:915 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-30 09:40:09:916 - info: [debug] [BOOTSTRAP] [debug] Got command action: find
2016-11-30 09:40:09:916 - info: [debug] [BOOTSTRAP] [debug] Finding .//*[@content-desc=‘Add’] using XPATH with the contextId: multiple: false
2016-11-30 09:40:09:968 - info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.Button, INSTANCE=1]
2016-11-30 09:40:09:987 - info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:{“ELEMENT”:“20”}}
2016-11-30 09:40:09:990 - info: [debug] Responding to client with success: {“status”:0,“value”:{“ELEMENT”:“20”},“sessionId”:“0011de81-da81-491e-8129-25a7f3213588”}
2016-11-30 09:40:09:991 - info: <-- POST /wd/hub/session/0011de81-da81-491e-8129-25a7f3213588/element 200 91.403 ms - 88 {“status”:0,“value”:{“ELEMENT”:“20”},“sessionId”:“0011de81-da81-491e-8129-25a7f3213588”}
2016-11-30 09:40:09:996 - info: --> POST /wd/hub/session/0011de81-da81-491e-8129-25a7f3213588/touch/perform {“actions”:[{“action”:“tap”,“options”:{“element”:“20”}}]}
2016-11-30 09:40:09:998 - info: [debug] Pushing command to appium work queue: [“element:getLocation”,{“elementId”:“20”}]
2016-11-30 09:40:10:006 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“element:getLocation”,“params”:{“elementId”:“20”}}
2016-11-30 09:40:10:010 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-30 09:40:10:010 - info: [debug] [BOOTSTRAP] [debug] Got command action: getLocation
2016-11-30 09:40:10:026 - info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:{“x”:1456,“y”:2368}}
2016-11-30 09:40:10:029 - info: [debug] Pushing command to appium work queue: [“element:getSize”,{“elementId”:“20”}]
2016-11-30 09:40:10:033 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“element:getSize”,“params”:{“elementId”:“20”}}
2016-11-30 09:40:10:036 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-30 09:40:10:036 - info: [debug] [BOOTSTRAP] [debug] Got command action: getSize
2016-11-30 09:40:10:072 - info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:{“width”:204,“height”:192}}
2016-11-30 09:40:10:074 - info: [debug] Pushing command to appium work queue: [“element:click”,{“elementId”:“20”,“x”:1558,“y”:2464}]
2016-11-30 09:40:10:083 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“element:click”,“params”:{“elementId”:“20”,“x”:1558,“y”:2464}}
2016-11-30 09:40:10:083 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-30 09:40:10:083 - info: [debug] [BOOTSTRAP] [debug] Got command action: click
2016-11-30 09:40:13:262 - info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:true}
2016-11-30 09:40:13:266 - info: [debug] Responding to client with success: {“status”:0,“value”:true,“sessionId”:“0011de81-da81-491e-8129-25a7f3213588”}
2016-11-30 09:40:13:267 - info: <-- POST /wd/hub/session/0011de81-da81-491e-8129-25a7f3213588/touch/perform 200 3271.188 ms - 76 {“status”:0,“value”:true,“sessionId”:“0011de81-da81-491e-8129-25a7f3213588”}
…’

And the UI element from getSource() can be found in the attachment UI.txtUI.txt (12.1 KB)
Also attached the snapshot of the uiautomatorviewer

1 - appium version ?
2 try:

  • ((AppiumDriver) driver).tap(1, addbtn, 200);
    3 try:
  • driver.findElement(MobileBy.id(“AddButton”)).click();
  • driver.findElement(MobileBy.className(“android.widget.Button”)).click();

Appium version 1.4.16.1, see the screenshot

When I used the driver.findElement(MobileBy.id(“AddButton”)).click();

got exception

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.09 seconds
For documentation on this error, please visit: Selenium
Build info: version: ‘3.0.1’, revision: ‘1969d75’, time: ‘2016-10-18 09:48:19 -0700’
System info: host: ‘PEKN50938276A’, ip: ‘10.128.214.191’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_112’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=C:\APK\android-Kapsel.apk, networkConnectionEnabled=true, warnings={}, app-package=com.piat.onlineOfflineAppTonySP14PL01, app-activity=.OnlineOfflineAppTonySP14PL01, databaseEnabled=false, deviceName=d8bc60eb, version=6.0.1, platform=WINDOWS, desired={app=C:\APK\android-Kapsel.apk, app-package=com.piat.onlineOfflineAppTonySP14PL01, app-activity=.OnlineOfflineAppTonySP14PL01, autoWebview=false, platformName=Android, deviceName=Android, version=6.0.1, platform=WINDOWS}, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, autoWebview=false, platformName=Android}]
Session ID: 7c847793-0876-4116-878d-75ebefa376ea
*** Element info: {Using=id, value=AddButton}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

…’

However there are multiple android.widget.Button in the page, I used the
(WebElement) driver.findElement(MobileBy.className(“android.widget.Button”)).get(1).click();

But still not got it clicked

When I used the ((AppiumDriver) driver).tap(1, addbtn, 200);

Got the log below.

2016-11-30 09:40:09:900 - info: [debug] Pushing command to appium work queue: [“find”,{“strategy”:“xpath”,“selector”:“.//[@content-desc=‘Add’]“,“context”:”“,“multiple”:false}]
2016-11-30 09:40:09:914 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:”.//
[@content-desc=‘Add’]”,“context”:“”,“multiple”:false}}
2016-11-30 09:40:09:915 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-30 09:40:09:916 - info: [debug] [BOOTSTRAP] [debug] Got command action: find
2016-11-30 09:40:09:916 - info: [debug] [BOOTSTRAP] [debug] Finding .//*[@content-desc=‘Add’] using XPATH with the contextId: multiple: false
2016-11-30 09:40:09:968 - info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.Button, INSTANCE=1]
2016-11-30 09:40:09:987 - info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:{“ELEMENT”:“20”}}
2016-11-30 09:40:09:990 - info: [debug] Responding to client with success: {“status”:0,“value”:{“ELEMENT”:“20”},“sessionId”:“0011de81-da81-491e-8129-25a7f3213588”}
2016-11-30 09:40:09:991 - info: ← POST /wd/hub/session/0011de81-da81-491e-8129-25a7f3213588/element 200 91.403 ms - 88 {“status”:0,“value”:{“ELEMENT”:“20”},“sessionId”:“0011de81-da81-491e-8129-25a7f3213588”}
2016-11-30 09:40:09:996 - info: → POST /wd/hub/session/0011de81-da81-491e-8129-25a7f3213588/touch/perform {“actions”:[{“action”:“tap”,“options”:{“element”:“20”}}]}
2016-11-30 09:40:09:998 - info: [debug] Pushing command to appium work queue: [“element:getLocation”,{“elementId”:“20”}]
2016-11-30 09:40:10:006 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“element:getLocation”,“params”:{“elementId”:“20”}}
2016-11-30 09:40:10:010 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-30 09:40:10:010 - info: [debug] [BOOTSTRAP] [debug] Got command action: getLocation
2016-11-30 09:40:10:026 - info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:{“x”:1456,“y”:2368}}
2016-11-30 09:40:10:029 - info: [debug] Pushing command to appium work queue: [“element:getSize”,{“elementId”:“20”}]
2016-11-30 09:40:10:033 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“element:getSize”,“params”:{“elementId”:“20”}}
2016-11-30 09:40:10:036 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-30 09:40:10:036 - info: [debug] [BOOTSTRAP] [debug] Got command action: getSize
2016-11-30 09:40:10:072 - info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:{“width”:204,“height”:192}}
2016-11-30 09:40:10:074 - info: [debug] Pushing command to appium work queue: [“element:click”,{“elementId”:“20”,“x”:1558,“y”:2464}]
2016-11-30 09:40:10:083 - info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“element:click”,“params”:{“elementId”:“20”,“x”:1558,“y”:2464}}
2016-11-30 09:40:10:083 - info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
2016-11-30 09:40:10:083 - info: [debug] [BOOTSTRAP] [debug] Got command action: click
2016-11-30 09:40:13:262 - info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,“value”:true}
2016-11-30 09:40:13:266 - info: [debug] Responding to client with success: {“status”:0,“value”:true,“sessionId”:“0011de81-da81-491e-8129-25a7f3213588”}
2016-11-30 09:40:13:267 - info: ← POST /wd/hub/session/0011de81-da81-491e-8129-25a7f3213588/touch/perform 200 3271.188 ms - 76 {“status”:0,“value”:true,“sessionId”:“0011de81-da81-491e-8129-25a7f3213588”}

why you use (WebElement)? your driver is WebDriver or AppiumDriver/AndroidDriver (only this one is correct)?

Hi,
I have tried click, tap, touch event for a ionic Cordova application… it is working at some buttons but in few places it was not working.
Tried with xpath, ID, x and y co-ordinate etc.
Test is passed, as if it clicked the concern element, but it is not redirecting to the next state if click was successful.
I am using Webview_com.xxx as context.
Capabilities set are App package, App activity, uniautomator2 etc…
Please help me with this struck here for past 2 days.
Went through many of ur comments, hope you will help me with this

Hi @saimeera22 , There may be a case when your application page doesn’t load at given time, in that scenario you can give explicit wait/sleep.
If you are doing it for android you can dump xml file of current page, to check if that element is present or not. There’s an adb command to do that: adb shell uiautomator dump /sdcard/view.xml
You can check out this youtube video: Source: https://youtu.be/wjEWRMbPk1Q
I hope it will help you, still have queries than comment below that video, I will be active to reply it all.

2 Likes

Hi
@Swapan_Chhabra
Thanks for your time.
Element is present even the click even it performed and then is passing but the app doesnt recognise tat even and redirecting to the next page.

Hello Guys,

I am facing the same problem.
Please help about the same

Anyone was able to resolve this problem?
I’m seeing similar problem. Reported details here:

1 Like

@AlekseiP why not to try:

  1. switch to TAP method instead of click
  2. you can always still use TAP by using x,y center of element you find

Yeah, that’s what I did.
Still not clean solution, I even cannot take coordinates for element. And tapping on element by coordinates introducing extra complexity because I need to manage x&y for all kind of devices.

@AlekseiP why you are not moving to tap method? just make ALL clicks points to one function. and play in one place as you wish…

@Aleksei for example I want to read text from element and then press on it.
My original problem is:
I can locate element using find_element, but cannot click, get location, get text. That makes sometimes impossible to create assertion or verify something.

@AlekseiP move to Appium annotation. 10x times easier to use. example -> https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java

Thank you @Aleksei I’ll try it. Will post update here.

@Aleksei tried to locate element using uiAutomator, observing same problem.

Better use “id =some_resourceID”. Once you have element and no need use “driver.find…” create tap/click function and root all actions there.

Then while investigationg the cause of fail you can easily to add e.g. sleep for some sec to check was animation caused it while you clicking too fast. Also now you can do click by x,y function that will accept element in base class and use it as final solution in problematic situations.