FiXiT FiXiT - 5 months ago 28
Android Question

How to Automate facebook login test using Appium in Android

Hi I am new to Appium testing. I am testing facebook login in my app but the problem is I am not able to select the ids in UIAutomatorViewer as it will open the facebook webview.So I tried switching the context from NATIVE to WEB but still its not working.

Here is the code

public void fbLogin() throws InterruptedException {
System.out.println("IN FB_LOGIN TEST ");
this.getDriver().context("NATIVE_APP");// set the context to Native; // click on the fb button in native app
Thread.sleep(10000); // sleep
Set<String> contextNames = getDriver().getContextHandles();
for (String contextName : contextNames) {
if (contextName.contains("WEBVIEW")) {

can some one suggest whats going wrong?

  1. Facebook login through the app:

    • you can use UIAutomatorViewer to get view ids like here, from this discussion;
    • you don't even need to "getDriver().context(contextName);" in this case (but not sure);
  2. Facebook login through WebView:

    • you have to debug the WebView (as a browser) to get needed elements xpath;
    • with the elements xpath (in my case email field xpath was "//*[@id='u_0_2']") you can search for a field WebElement element = driver.findElementByXPath("//*[@id='u_0_2']") and then click on it or type something whatever;
  3. Don't have any solution if it's in the browser.