Call to 'sendKeys' failed on android emulator

this UI element is a native input with the outer container
on Appium inspector
the outer container is
class: android.view.ViewGroup

the inner native input text
class:android.widget.EditText

this input text has testID and accessiblityLabel set to PhoneNumberInput
I got this error
Call to ‘sendKeys’ failed
Cannot set the element to ‘888888’. Did you interact with the correct element?
when running the automation,
I used the appium inspector
to search for element
Locator strategy: Accessiblity Id
and selector: PhoneNumberInput

however I am able to tapElement but not sendKeys

I would trust the logs here. If it’s the correct element, probably need to click it first before sending keys.

I have tap element (which mean it’s clicked) then I send keys
but it got the error

I post another log here

I noticed some java thread event in the log

this does not happen in iOS Simulator

but it happen in android emulator

When you have tapped, does the element change so that it has a cursor? The automation should work just like a user would. Often the user will need to click to make the element active and then input text. Can you watch your automation to see that this is happening?

yes I saw it , when I tap element, there is a cursor

Can you do that with Inspector? Click it and check the element. Make sure you are sending to the correct one.

I am doing with the Appium inspector.

Interesting. I’ve never used the search for this. I always search the xml hierarchy and go in that way. Looks like a bug to me. Thanks for the movie, that helps a lot.

here: https://gist.github.com/LayMui/3ed1e94fdd71886b9cbb4e69b5e15085
you locate the element with this selctor:

//android.view.ViewGroup[@content-desc=\"PhoneNumberInput\"]/android.view.ViewGroup[1]

you can see that the element is from class: android.view.ViewGroup and not! from class: android.widget.EditText

as well the response you are getting returns the following elementId:

5106fa94-28e4-469b-b4bf-220c88a1f516
  • you can search for it with command + f and see the interactions for yourself in the gist

when you send the keys you are sending it to the same elementId, meaning you are sending the keys to an element from class: ‘android.view.ViewGroup’

[debug] e[35m[WD Proxy]e[39m Proxying [POST /element/5106fa94-28e4-469b-b4bf-220c88a1f516/value] to [POST http://127.0.0.1:8200/wd/hub/session/df923f05-5427-4dd2-882e-b59c82ab718c/element/5106fa94-28e4-469b-b4bf-220c88a1f516/value] with body: {"elementId":"5106fa94-28e4-469b-b4bf-220c88a1f516","text":"12121","replace":false,"value":["1","2","1","2","1"]}

solution:
inside the ViewGroup element which you already clicked on you probably have an ‘android.widget.EditText’ element(nested); so, you need to locate the EditText element from the ViewGroup element.

something like the following:

WebElement viewGroupElement = driver.findElement(By.xpath("ViewGroup Selector"));
viewGroupElement.click(); //or tap...
WebElement editTextElement = viewGroupElement.findElement(By.class("android.widget.EditText")); //or By.xpath("//android.widget.EditText[1]")
editTextElement.sendKeys("your phone number");