Hello Appium team,
I have one basic question in mind. Can i use the same Android finding mechanism(UiAutomator) with Appium.
I am not good in UiAutomator though, just playing around.
When i launch phone/emulator, it comes with Home screen and i need to click on "Apps" control, for that i think below command can find Apps control
new UiObject(new UiSelector().description("Apps"))
I want to execute this command to find the control through Appium(though i know we can use other appium finding mechanism to do this)
I tried below code, but getting exception. Can you please help me where i am going wrong?
public class executeAndroidCommands
{
public static void main(String[] args)
{
AndroidDriver driver=null;
DesiredCapabilities caps=new DesiredCapabilities();
caps.setCapability("deviceName", "emulator-5554");
caps.setCapability("appPackage", "com.android.launcher");
caps.setCapability("appActivity", "com.android.launcher2.Launcher");
try
{
driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),caps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
} catch (MalformedURLException e)
{
e.printStackTrace();
}
driver.findElementByAndroidUIAutomator("new UiObject(new UiSelector().description(\"Apps\"))").click();
}
}
Below is the log:
info: <-- POST /wd/hub/session/332a8b9f-321c-463c-b9a2-7d654509c81a/timeouts/implicit_wait 200 8.788 ms - 76 {"status":0,"value":null,"sessionId":"332a8b9f-321c-463c-b9a2-7d654509c81a"}
info: --> POST /wd/hub/session/332a8b9f-321c-463c-b9a2-7d654509c81a/element {"using":"-android uiautomator","value":"new UiObject(new UiSelector().description(\"Apps\"))"}
info: [debug] Waiting up to 20000ms for condition
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"-android uiautomator","selector":"new UiObject(new UiSelector().description(\"Apps\"))","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiObject(new UiSelector().description(\"Apps\"))","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding new UiObject(new UiSelector().description("Apps")) using ANDROID_UIAUTOMATOR with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Parsing selector: new UiObject(new UiSelector().description("Apps"))
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":9,"value":"Could not parse UiSelector argument: UiSelector has no new UiObject method"}
info: [debug] Waited for 65ms so far
info: [debug] Pushing command to appium work queue: ["find",{"strategy":"-android uiautomator","selector":"new UiObject(new UiSelector().description(\"Apps\"))","context":"","multiple":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiObject(new UiSelector().description(\"Apps\"))","context":"","multiple":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding new UiObject(new UiSelector().description("Apps")) using ANDROID_UIAUTOMATOR with the contextId: multiple: false
info: [debug] [BOOTSTRAP] [debug] Parsing selector: new UiObject(new UiSelector().description("Apps"))
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":9,"value":"Could not parse UiSelector argument: UiSelector has no new UiObject method"}