Need to locate the elements in an hybrid apps

Hi
I have successfully automated a native app without any problems, but I could not locate the elements in a hybrid app. Even i got the html file of the hybrid app and given the element id, but appium could not recognise it. Can anyone please help me with the additional code required for working with a Hybrid app.

Have you tried getcontextHandles method? or setting the context to Webview and then trying to find element?

Hi Mayuresh,

Thanks for your reply.
While I use getvontextHandles method its asking to add cast to the driver… Why is it So? And even after adding it i m unable to locate the elements. Can you share me a proper code to set the context to webview.

Java Client:2.1.0

capabilities = new DesiredCapabilities();
//capabilities.setCapability(“platformName”,“Android”));
capabilities.setCapability(“deviceName”,“HTC”);
capabilities.setCapability(“platformVersion”, “4.4”);
capabilities.setCapability(“app”, “C:/”);
capabilities.setCapability(“newCommandTimeout”, “500”);
driver=new AndroidDriver(new URL(“http://0.0.0.0:4723/wd/hub”), capabilities);

system.out.println(driver.getcontextHandles());
driver.context(“WebView”);

My driver is not listing the getcontextHandles() method. I am using the appium driver only… While typing the method mannually its asking to cast the driver…

Is Java client installed in build path?

Yes everything installed…

@amarnath
Add java-client-xx.jar to your project. The you can type case your driver to (AppiumDriver) driver.

I am desperately planning to automate a native app but failed to do as unable to do recognize the elements through program i.e using driver.PageSource ( as my requirement is like that)----Can you please help me how U have achieved automating native app using appium. For Hybrid app better U connect your mobile to PC and open chrome and from there U can navigate to the app in the device using the command chrome://inspect/devices#devices after opening the same screen in device. By hovering any element on the screen displayed on the browser U can get the details of that element in Chrome but the same is impossible for me to check for native apps using the above procedure hence I request to help me regarding this…

@amarnath

Try using the latest Java client. Also in some hybrid apps the context names can be different, Like

WEBVIEW_1 or WEBVIEW_App_Package

Try to find out exact package name and then use driver.context(“ContextName”);

To find out Webview locators for hybrid app , Use Chrome remote debugger.

Hope this will help.

Regards
Ravi Kumar