In Appium, I am able to click the element, but sendKeys not working

Hi,
I am working on hybrid app for appium automation using emulator. This app is developed using Ionic framework. I am unable to use sendKeys method for web element inside webview. I am able to click that element, but sendKeys is not working and throwing error as "An unknown server-side error occurred while processing the command. Original error: unknown error: cannot focus element"

Appium 1.9.0 ; Chrome 61; Chrome driver 2.33 / 2.34 ; Java client 6.1.0

Below is my code:

package packageSeptNine;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.FindsByAndroidUIAutomator;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;

public class EmulSmartView
{
@Test
public void test_qual3() throws InterruptedException {
AppiumDriver driver = null;

	DesiredCapabilities caps = new DesiredCapabilities();
	
	caps.setCapability("deviceName", "Phone");
	caps.setCapability("udid", "emulator-5554");
	//caps.setCapability("platformName", "Android");
	//caps.setCapability("platformVersion", "8.1.0");
	caps.setCapability("appPackage", "io.ionic.starter");
	caps.setCapability("appActivity", "io.ionic.starter.MainActivity");
	//caps.setCapability("autoWebview", "true");
	caps.setCapability("browserName", "");
	caps.setCapability("automationName", "appium");
	//caps.setCapability("noReset", "true");
	
	caps.setCapability("chromedriverExecutable", "D:\\Browser Drivers\\Chrome2_34\\chromedriver.exe");
	
	try {
			driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
		
	} catch (MalformedURLException e) {
		System.out.println(e.getMessage());
	}

	driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
	
	Thread.sleep(10000);
	
	System.out.println("Context count is "+driver.getContextHandles().size());
	
	System.out.println("name of context is "+ driver.getContextHandles());
	
	Set<String> conName=driver.getContextHandles();
	
	Thread.sleep(3000);
	
	for (String cont:conName)
	{
		System.out.println(cont);
		if(cont.contains("WEBVIEW_io.ionic.starter"))
		{
			driver.context(cont);
			System.out.println("I am in webview");
			break;
		}
	}
	
	Thread.sleep(5000);
	driver.findElement(By.id("userName")).sendKeys("abcd");
	
	//driver.findElement(By.id("password")).click();
	Thread.sleep(5000);
	//driver.quit();
	}

}

Error message:

[RemoteTestNG] detected TestNG version 6.7.0
[TestNG] Running:
C:\Users\yu251666\AppData\Local\Temp\testng-eclipse–1160080088\testng-customsuite.xml

Sep 20, 2018 3:54:00 AM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Context count is 3
name of context is [NATIVE_APP, WEBVIEW_chrome, WEBVIEW_io.ionic.starter]
NATIVE_APP
WEBVIEW_chrome
WEBVIEW_io.ionic.starter
I am in webview
FAILED: test_qual3
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: unknown error: cannot focus element
(Session info: chrome=61.0.3163.98)
(Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 10.0.16299 x86_64)
Build info: version: ‘3.14.0’, revision: ‘aacccce0’, time: ‘2018-08-02T20:05:20.749Z’
System info: host: ‘L-285000932’, ip: ‘192.168.0.13’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_144’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: io.ionic.starter.MainActivity, appPackage: io.ionic.starter, automationName: appium, browserName: , chromedriverExecutable: D:\Browser Drivers\Chrome2_…, databaseEnabled: false, desired: {appActivity: io.ionic.starter.MainActivity, appPackage: io.ionic.starter, automationName: appium, browserName: , chromedriverExecutable: D:\Browser Drivers\Chrome2_…, deviceName: Phone, platformName: android, udid: emulator-5554}, deviceManufacturer: Google, deviceModel: Android SDK built for x86, deviceName: emulator-5554, deviceScreenSize: 1080x1920, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: Android, platformVersion: 8.1.0, takesScreenshot: true, udid: emulator-5554, warnings: {}, webStorageEnabled: false}
Session ID: 0932d392-23e8-4455-b8fb-6cbf5ae620d4
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276)
at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:100)
at packageSeptNine.EmulSmartView.test_qual3(EmulSmartView.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:715)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:907)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1237)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:51)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:85)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
at org.testng.TestNG.run(TestNG.java:1030)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0

===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0

[TestNG] Time taken by [email protected]: 22 ms
[TestNG] Time taken by [email protected]: 17 ms
[TestNG] Time taken by [email protected]: 65 ms
[TestNG] Time taken by [TestListenerAdapter] Passed:0 Failed:0 Skipped:0]: 12 ms
[TestNG] Time taken by [email protected]: 6 ms
[TestNG] Time taken by [email protected]: 52 ms

Until a few days ago, it worked normally. But there was some update on the new version of the application or the chrome driver on the phone (automatically updated by the playstore). Then send_keys crashed.

I use Ruby + Capybara + PageObject in an Angular / Ionic project.

It was working normally, with no major problems. But with this send_keys problem it leaves a huge hole in the automation project.

Does anyone know how to fix this send_keys problem? is it appium? of the driver?

waiting feedback.

Until a few days ago, it worked normally. But there was some update on the new version of the application or the chrome driver on the phone (automatically updated by the playstore). Then send_keys crashed.

I use Ruby + Capybara + PageObject in an Angular / Ionic project.

It was working normally, with no major problems. But with this send_keys problem it leaves a huge hole in the automation project.

Does anyone know how to fix this send_keys problem? is it appium? of the driver?

waiting feedback.

Hi Did you find solution to this problem ? Even I’m facing the same issue.

@coolvasanth can you provide your issue log here ? To look into your problem.

@pothurajtharun Hi thanks for replying. I’m using Ionic Application, which is a Hybrid Mobile application. So I will be changing context to webview and execute my test cases. I’m able perform tasks like clicking with the HTML id. But facing problem whenever I try to sendKeys to Input box via ID or ClassName.
This link will explain, why it might not be working.


But it is almost an year after above post, I anticipate a fix from Appium for this.

Note: I know using Xpath would solve this problem. But since it is a Hybrid app, I need to use same script for both Android and iOS, so using ID would be my first priority.