question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to identify elements on Webview using Java

See original GitHub issue

The problem

We have a salesforce app built using react native for iOS and Android. The first screen that shows up on launching app is a WebView with username/password and login button. The activity of this screen is com.salesforce.androidsdk.ui.LoginActivity. Appium is able to successfully install and launch the app but is not able to sendkeys in username field or interact with any other element on the page.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.6.5
  • Last Appium version that did not exhibit the issue (if applicable): NA
  • Desktop OS/version used to run Appium: Mac 10.12.5
  • Node.js version (unless using Appium.app|exe): 6.11.1
  • Mobile platform/version under test: Android 7.1.1
  • Real device or emulator/simulator: Emulator and Real device is Android 6.0.1
  • Appium CLI or Appium.app|exe: CLI

Details

We have a salesforce app built using react native for iOS and Android. The first screen that shows up on launching app is a WebView with username/password and login button. The activity of this screen is com.salesforce.androidsdk.ui.LoginActivity. Appium is able to successfully install and launch the app but is not able to sendkeys in username field or interact with any other element on the page.

Link to Appium logs

https://gist.github.com/jineshqa/2499010a84c347a4aef5b8355a47ebc2

Code To Reproduce Issue [ Good To Have ]

import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;

/**
 * Created by Jinesh on 8/17/17.
 */
public class demoTestCase {

    public static void main(String [] args) throws MalformedURLException {

        File f = new File("app");
        File fs = new File(f,"app-debug.apk");


        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.DEVICE_NAME,"DEVICE_NAME");
        cap.setCapability(MobileCapabilityType.APP,fs);
        cap.setCapability("recreateChromeDriverSessions", true);
        cap.setCapability("appPackage","com.xxxx.scanner");
        cap.setCapability("appActivity",".MainActivity");
        cap.setCapability("appWaitActivity","com.salesforce.androidsdk.ui.LoginActivity");
        cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT,"300");
        cap.setCapability("automationName","uiautomator2");

        AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        driver.context("WEBVIEW_com.xxxx.scanner");

        driver.findElement(By.className("username")).sendKeys("secret");
        driver.findElement(By.id("password")).sendKeys("secret");
        driver.findElement(By.id("Login")).click();
        

    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jineshqacommented, Apr 10, 2018

@SteffyVarghese1 upgrade to latest or downgrade to https://mvnrepository.com/artifact/io.appium/java-client/5.0.4. Try a couple of versions and see. Also, note that for me the first page was Webview and so I had to switch context.

1reaction
jineshqacommented, Aug 30, 2017

@jlipps @priyankshah217 @pavanbachu0604 Its working after I upgraded from java-client-5.0.0-BETA9.jar to latest.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to locate webelements of hybrid app using appium ...
It seem like, you wrong at the line: driver.context("WEBVIEW_com.lodgistics.connect");. Use the bellow code: Set<String> context = driver.
Read more >
Can't find elements on a webview page of an android Native ...
I am not able to find the elements from android.webkit.WebView in my native app. As you can see in the uiautomatorviewer, I am...
Read more >
Unable to click/tap on a button in Android WebView
This is a webview in Android native app. So I switched context to Webview, then able to detect the element and getText of...
Read more >
Finding elements in Mobile Applications - Endtest
Know your locators ; Android UI Automator, Use the UI Automator API, in particular the UiSelector class to locate elements. In Appium you...
Read more >
No ability to identify WebView's child elements on Salesforce ...
WebView tag, and we used the Appium GUI tool to inspect. We were able to inspect the native elements, but we can't see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found