Appium 1.2: In Android, How to click on native app button that only has text, class and package?

847 views
Skip to first unread message

Saimadhu G

unread,
Aug 7, 2014, 4:58:28 AM8/7/14
to appium-...@googlegroups.com
Hi,

I am clicking on the native button, we can see the button pressed. But the next screen is not coming up when clicked through automation.
If clicked manually it is working.

Environment:
---------------------
Appium 1.2
Java-client 1.6.1

button properties:
-----------------------------------
index: 2
text: Done
class: android.widget.Button
content-desc: 
package: com.Android.CAMDM
resource id: 
checkable: false
checked: false
clickable: true
enabled: true
focusable: true
focused: false
scrollable: false
long-clickable: false
is password: false
selected: false


Code snippet to click on  button:
-------------------------------------------------------
try{
//In the page only 1 button with text Done is present. click on Done button
List<WebElement> buttons =driver2.findElementsByClassName("android.widget.Button");
WebElement b1 = buttons.get(0);
String text = b1.getText();

WebElement button1=driver2.findElement(By.name(text));
boolean x = button1.equals("android.widget.Button");
boolean y = button1.isEnabled();

button1.click();
b1.click();
} catch (Exception e){
System.out.println(e);
}

Also, tried to click as below:
-----------------------------------------
try{
WebElement button1=driver2.findElement(By.name("Done"));
button1.click();
// button1.sendKeys("\n");
} catch (Exception e){
System.out.println(e);
}


public static DesiredCapabilities setDeviceCap() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "Appium");
//
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");  
capabilities.setCapability("appium-version", "1.2.1.0");
// capabilities.setCapability("deviceName", "sony-c6602-BX903J4SHE");

capabilities.setCapability("deviceName", "mdmqa");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("newCommandTimeout", "6000");
capabilities.setCapability("platformVersion", "4.4.2");
// capabilities.setCapability("app", "D://Desktop//MDM//GEN07112954E//GEN07112954E//Clients//Android//CAMDM.apk");
capabilities.setCapability("app", "C://Users//ganma05//Desktop//Appium//q2sp1//CAMDM.apk");
capabilities.setCapability("appPackage", "com.Android.CAMDM");
capabilities.setCapability("appActivity", "com.Android.Afaria.Afaria");
return capabilities;
}



APPIUM Server log when clicked on Done button: //detailed log attached
-----------------------------------------------------------------------
> info: --> POST /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element {"using":"name","value":"Done"}
> debug: Appium request initiated at /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element
> warn: [DEPRECATED] The name locator strategy has been deprecated and will be removed.  Please use the accessibility id locator strategy instead.
> debug: Request received with params: {"using":"name","value":"Done"}
> debug: Pushing command to appium work queue: ["find",{"strategy":"name","selector":"Done","context":"","multiple":false}]
> debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"name","selector":"Done","context":"","multiple":false}}
> debug: [BOOTSTRAP] [debug] Got command of type ACTION
> debug: [BOOTSTRAP] [debug] Got command action: find
> debug: [BOOTSTRAP] [debug] Finding Done using NAME with the contextId:  multiple: false
> debug: [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=Done, INSTANCE=0]
> debug: [BOOTSTRAP] [debug] Using: UiSelector[TEXT=Done, INSTANCE=0]
> debug: [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"2"},"status":0}
> info: <-- POST /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element 200 36.928 ms - 87 {"status":0,"value":{"ELEMENT":"2"},"sessionId":"c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d"}
> debug: Responding to client with success: {"status":0,"value":{"ELEMENT":"2"},"sessionId":"c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d"}
> info: --> GET /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element/2/enabled {}
> debug: Appium request initiated at /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element/2/enabled
> debug: Request received with params: {}
> debug: Pushing command to appium work queue: ["element:getAttribute",{"elementId":"2","attribute":"enabled"}]
> debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getAttribute","params":{"elementId":"2","attribute":"enabled"}}
> debug: [BOOTSTRAP] [debug] Got command of type ACTION
> debug: [BOOTSTRAP] [debug] Got command action: getAttribute
> debug: [BOOTSTRAP] [debug] Returning result: {"value":"true","status":0}
> debug: Responding to client with success: {"status":0,"value":true,"sessionId":"c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d"}
> info: <-- GET /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element/2/enabled 200 14.032 ms - 76 {"status":0,"value":true,"sessionId":"c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d"}
> info: --> POST /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element/2/click {"id":"2"}
> debug: Appium request initiated at /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element/2/click
> debug: Request received with params: {"id":"2"}
> debug: Pushing command to appium work queue: ["element:click",{"elementId":"2"}]
> debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"2"}}
> debug: [BOOTSTRAP] [debug] Got command of type ACTION
> debug: [BOOTSTRAP] [debug] Got command action: click
> debug: [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> debug: Responding to client with success: {"status":0,"value":true,"sessionId":"c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d"}
> info: <-- POST /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element/2/click 200 173.395 ms - 76 {"status":0,"value":true,"sessionId":"c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d"}
> info: --> POST /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element/1/click {"id":"1"}
> debug: Appium request initiated at /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element/1/click
> debug: Request received with params: {"id":"1"}
> debug: Pushing command to appium work queue: ["element:click",{"elementId":"1"}]
> debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"1"}}
> debug: [BOOTSTRAP] [debug] Got command of type ACTION
> debug: [BOOTSTRAP] [debug] Got command action: click
> debug: [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> debug: Responding to client with success: {"status":0,"value":true,"sessionId":"c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d"}
> info: <-- POST /wd/hub/session/c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d/element/1/click 200 144.924 ms - 76 {"status":0,"value":true,"sessionId":"c0c58dd4-62f9-4f65-9ff2-26bc8cea9e8d"}


Done_button_not_taking_to_next_screen.png
appiumLog.txt

Isaac Murchie

unread,
Aug 7, 2014, 11:40:00 AM8/7/14
to Saimadhu G, appium-...@googlegroups.com
My first guess would be that your app is catching a different event. Click vs. long click vs. touch, etc. I would experiment with that avenue. You could try using the TouchAction API and tap, for instance.




--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

Saimadhu G

unread,
Aug 8, 2014, 10:48:21 AM8/8/14
to appium-...@googlegroups.com, madhusud...@gmail.com
Thanks Isaac for the reply. I did touch action apis, but still the same problem.
We debugged in our apk file and found there is a == comparison to compare 2 charsequences for the button name clicked.
After changing toString and equal comparison, now automation (click, tap, longclick) and manual both are working.

Still not sure why it was working with manuallly but not with automation.

Thanks
Saimadhu
Reply all
Reply to author
Forward
0 new messages