Appium: Android - sendKeys() function clicks/taps random elements in the page but does not enter text in the EditText element.

Created on 22 Dec 2014  Â·  71Comments  Â·  Source: appium/appium

Hello,

I have been stuck with this issue for a few days now.

I am executing a script which has to type some text in a search box present in the page.
When ever the sendKeys() command is executed, the control clicks/taps other elements (e.g. TextView element) in the page but does not type anything in the EditText element.

I am using
Appium Version 1.3.3
Android Version 4.4.2
(this behaviour is consistent on all android 4.4.2 devices)
I also tried to use the sendKeys function in the Appium Inspector, and the behaviour is consistent.

I have tried to insert text/type an alphabet using KeyCode - driver.sendKeyEvent(29).
But this also causes the same strange behaviour.

Please advice.

Android Bug

Most helpful comment

I think I had the same issue with sendKeys. After investigating, I found that after using click(), the values returned by getLocation() had changed, but the element had not moved in the UI.
I solved the problem by finding the element again, using findElementById(), before calling sendKeys()

element = driver.findElementById("id/editTextBox");
element.click();
element = driver.findElementById("id/editTextBox");
element.sendKeys(value);

All 71 comments

Could you try using the latest Appium (1.3.4)?

Hey I just tried with Appium 1.3.4. The issue still exists.

It will be helpful to see the appium server log, could you paste it in a gist or something and post the link to it?

Hello,

I have uploaded the appium server log for the 'entering Text in search field' on google doc -
https://drive.google.com/file/d/0ByUFFwFhPcyGSnlCenM0U0huVDg/view?usp=sharing

Please let me know if you need the entire log.

So you're trying to send keycode 4 (Back key)?

Sorry,
Ya i was pressing the back key for a different reason. Please ignore that part.
First I tap on the textbox > then press back button > then type the text Newark, NJ

Note
The same is observed even when the press back button step is skipped.

Please post (a link to) the complete log if possible.

The log looks fine to me, sounds like it detects the hint and sends the text correctly. I'm just a bit worried about the Back key you're sending right before the call to sendKeys. Would it still fail if you click the textbox first?

Ok... let me cross check it once again and send you the new logs without the back keypress hang on..

Also try to see what happens if you click on the element first:

el.click()
el.send_keys("foo")

Did you also try to click on the element (in the log above)?

Yes, that is what I am doing.
When i click on the EditText element, the cursor appears in the textbox...

The log sounds a bit inconsistent, you're clicking on an element with id 14, but sending the text to an element with id 12...

I am clicking on and entering text for the element with resource ID - com.APPNAME.android:id/filter_location

I do not know why appium is returning a different element IDs for the same element

How does your test look like?

I put the clicking and entering text in the same function now.

Now both the actions are performed with the same element ID (but nothing gets typed) - please check

https://drive.google.com/file/d/0ByUFFwFhPcyGLUNDTHQxMXV1WVk/view?usp=sharing

My code is as below

element.click();
element.sendKeys(value);

Click works fine, but nothing is typed in the text field.

mmm, I'd say it must be something with that EditBox. We might be able to help if we could get a copy of your apk to test.

K... I'll get back to you on that by tmro....
Thanks a lot.... really appreciate it

Hello paymand,
How should i be sharing the apk file with you?

Just put it on some server and post a download link if possible.

Please find the below link to download the apk file -
https://drive.google.com/file/d/0ByUFFwFhPcyGcmxMblZUeERJdTQ/view?usp=sharing

Once the apk is installed, please click on search icon on the top right corner.
Search page is displayed. The EditBox with the issue is the one on top of the page where user can type in a search location.

Please let me know if you need more info.

Thanks and Regards,
Poorvika

I can reproduce the issue in your app. Looks like this only happens with that specific textbox (sendKeys works with the textbox in create account page for instance). Is that a custom view or AutoCompleteTextView or something?

No, it is an EditText element. Below are the properties of the element -

content-desc:

type: android.widget.EditText

text: Current Location

index: 0

enabled: true

visible: true

location: {52, 33}

size: {538, 40}

checkable: false

checked: false

focusable: true

long-clickable: true

package: com.APPNAME.android

password: false

resource-id: com.APPNAME.android:id/filter_location

scrollable: false

selected: false

xpath: //android.widget.LinearLayout[1]/android.view.View[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.LinearLayout[2]/android.widget.EditText[1]

This is not an Appium issue since you cannot enter text using a simple adb command either.
Try tapping on the element to focus it and then run adb shell input text "foo".
(Same command works for other EditText elements in your app).

I think it's best if you ask the app developer to look into the issue and try to make the following steps work:

  1. Tap on the element to focus it.
  2. Run adb shell input text "foo".

Hi Paymand,

I also tried doing the same with my Application and having the same issue it doesn't type anything in the text feild when multiple feilds are there in single page.

Both through Appium and ADB command same issue is there but when I am trying to do the same for my login screen it works fine.

So I spoke with my developers they also not able to find the issue so can you please suggest any solution for this issue ??

Thanks,
Nischal Sinha

@Nischalapp: If they couldn't fix the issue, then I don't think I can be of much help. Maybe try to ask them to change the app layout a bit and try to see if that helps.

Hi Paymand,

I checked with developers but they are saying there is no any issues with Application. I was having old .apk file of my application with which previously Appium was working fine but now only I m getting this issue with Android. Lot of people is getting this issue when multiple textbox are present then sendkeys is not able to send any text in the text box and tapping in some other text feild.

Please can you guys check this or try to reproduce with any sample which is with you in which multiple text boxes are present. I raised the issue in github and lot of people are also raised this issue. But no one is looking into it. Please try to do something.

Hoping for the best.

Thanks in advance,
Nischal

@Nischalapp I've attempted to reproduce on a simple view with multiple android.widget.EditText elements on it and have come up with nothing. Can you give more information on what you are seeing happen? Logs are good, as is a minimal reproducing example.

I also can't reproduce with the Trulia app above.
trulia

Hi imurchie,

I did alot R & D and tried with two apps.

  1. Kizeo Me
  2. Trulia (same as above)

I tried sending text through adb shell input text "ABC" or adb shell input keyevent press_keycode 45. So for Kizeo Me app I am able to send the text sucessfully in editbox. Basically in this app for all edit boxes no any conditions are checked while typing in to editbox at runtime.

But the same commands I tried adb shell input text "ABC" or adb shell input keyevent press_keycode 45
in trulia app and its not working. Instead of typing in to text box , its tapping somewhere else. And in this app for editboxes like Address, year built, MLS and Keyword when type anything inside the textbox the condition is checked at runtime .

So, this is what I can understand from my analysis that wherever the condition is while typing into textbox its tapping in somewhere else instead of typing into textbox but when no condition is checked and edit box is simple its able to type.

I dont have much knowledge in Development but this is what I can understand from this analysis . Same thing is happening with appium also my test is getting passed .Suppose I m getting multiple email ids from as input from excel sheet and typing in to my Email textbox present in createaccount page app where multiple textboxes are present then its just taps here n there but nothing is visible in textbox and after finishing of one Email input , it takes another one like this it takes all input just types invisibly but nothing is really get typed in edit textbox. Attached appium logs for reference.

I contacted my developers also and they told condition is getting checked at runtime when u types
anything in Email textbox to check for valid email id.

Please Give your comments with this findings.

Appium log:

https://gist.github.com/paymand/e3ec6db8d478c34f359e

Thanks in advance,
Nischal Sinha

@Nischalapp: Moved the log to a gist. Please refrain from posting long logs in your comments.
@imurchie: Did you also try running the app on device? I could reproduce the issue on device fwiw.

Thanks for your support.

I tried on Android device only with adb shell command and I was not able
to enter anything into text box for app in which condition is checked at
runtime. (Trulia app)

Thanks,
Nischal Sinha

On Wed, Jan 14, 2015 at 3:54 PM, Payman Delshad [email protected]
wrote:

@Nischalapp https://github.com/Nischalapp: Moved the log to a gist.
Please refrain from posting long logs in your comments.
@imurchie https://github.com/imurchie: Did you also try running the app
on device? I could reproduce the issue on device fwiw.

—
Reply to this email directly or view it on GitHub
https://github.com/appium/appium/issues/4297#issuecomment-69896320.

_Nischal Sinha_
_Reach me : +919980072438_

Does this still persist?

Need to check.. From long time not worked on this

On Thu, Feb 12, 2015 at 12:07 AM, Isaac A. Murchie <[email protected]

wrote:

Does this still persist?

—
Reply to this email directly or view it on GitHub
https://github.com/appium/appium/issues/4297#issuecomment-73936934.

_Nischal Sinha_
_Reach me : +919980072438_

Yes Payman still I m facing the issue with latest Appium 1.3.4

On Thu, Feb 12, 2015 at 10:26 AM, Nischal Sinha [email protected]

wrote:

Need to check.. From long time not worked on this

On Thu, Feb 12, 2015 at 12:07 AM, Isaac A. Murchie <
[email protected]> wrote:

Does this still persist?

—
Reply to this email directly or view it on GitHub
https://github.com/appium/appium/issues/4297#issuecomment-73936934.

_Nischal Sinha_
_Reach me : +919980072438_

_Nischal Sinha_
_Reach me : +919980072438_

The issue still persists... !! even with appium 1.3.4

Latest Appium is 1.3.5.

I tried with appium 1.3.5
The issue is still there... I am still unable to type anything in the search location field.

Appium 1.3.4 does not work well with Android 4.4.2. You should try it on Android 4.3.

I think I had the same issue with sendKeys. After investigating, I found that after using click(), the values returned by getLocation() had changed, but the element had not moved in the UI.
I solved the problem by finding the element again, using findElementById(), before calling sendKeys()

element = driver.findElementById("id/editTextBox");
element.click();
element = driver.findElementById("id/editTextBox");
element.sendKeys(value);

fb_username=$app.find_element_by_xpath "//*[contains(@resource-id, 'login_username')]"
username= fb_user['email']
fb_username.click
fb_username.send_keys(username)

Friends in the above ruby code, I am trying to enter the emailid in FaceBook app to login. However the sendkeys function is slicing the domain name and hence my login is failing.

How do i use the adb command in a ruby file to enter the user name in the Facebook username field.

Thanks in advance.

i had the same issue up ,it cant works with the appium 1.3.7

I had same issue with send keys. but it was working, when findElementByAndroidUIautomator method was used to select the element with UiSelector concept instead of findElemetById/Xpath/Text

    driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"resource_id_of the_element\").instance(1)").sendKeys("input_data")

Note: I am using appium latest version of 1.4.0.0

@nanthu01 can you paste appium logs? may in a gist?

@moizjv I have attahced appium logs in gist, please find it in below link

https://gist.github.com/04b5fce26fb332cc4400.git

@moizjv please ignore the previous link, find the below link for your reference

https://gist.github.com/nanthu01/04b5fce26fb332cc4400

Also have same problem with appium 1.4.0 (this is on windows), but just on one specific EditText field. adb commands are not helpful also. DEV team will not change anything there. Any suggestion?

Try to use adb directly, it works for me:

  • I have a device with:
    deviceAddress = "192.168.56.101:5555"
    ;text = this%sIs%sMy%sText;
  • Text field should be activated (try element.click() with wd) then try:
    exec("adb -s "+deviceAddress+" shell input text "+text)
  • If you need to send special characters use this before send text:
    text = text.replace(/[$&+,:;=?@#|'<>.^*()%!-]/g,'\$&')

No, adb commands do not work, so its not even an appium issue.

Try the latest appium this issue is resolved and actually this was in
android.
On Oct 8, 2015 10:46 PM, "tfcardoso" [email protected] wrote:

No, adb commands do not work, so its not even an appium issue.

—
Reply to this email directly or view it on GitHub
https://github.com/appium/appium/issues/4297#issuecomment-146628293.

I tried with appium 1.4.14 and 1.4.8 from npm with wd client (using: setText(), sendKeys(), keys()...)
still not working with some input text fields in app.

Yes, this issues is still appearing with some input text fields, i tried on the new version of appium 1.4.13.1, the code is able to find out the field with the id or name but it is not sending parameter through sendkeys.

I am also facing the same issue. Its not working for EditText field. Any way to resolve this?

Hi Poorvikamahesh,

Have found solution for this issue...

I am also facing same issue with appium 1.5.3 for android using Java, it clicks and clear the edittext field but when sendkeys method execute it enter text in some other field.

Can any help me on this issue!!!!

I would appreciate your help.

Thanks,
Dani

Ok, so revisiting this issue. What about the latest latest version of Appium, 1.5.3?
With version 1.5 we did a major rewrite, so there is a chance that the issue is fixed or easier to debug.

Try using a List of MobileElement and then sending the text on the last element of the list.
when I checked appium server request and responses i found that 2 elements were found after the search with the given xpath, and the send keys was executed on the first element, which caused accidentally and always a click on another element (I don’t know why )
But when I tried making the sendKeys on the second element it worked fine (and I still don’t know why !!! )
Example
List <MobileElement> elements = driver.findElements(By.xpath("//*[@id='id’]")) ;
Elements.get(elements.size() -1).sendKeys(“text”);
So, just give it a try. I tried every solution proposed, but no one worked for me, except this.
Share :)

@fabytta - I have tried this but it is not working. However, I have used adb command to type in text box.
@Jonahss - I am using v1.5 and till this issue appear to me

I dont see SendKeyEvent or pressKeyCode in appiumdriver instance. Using AppiumForWindows 1_4_13_1. Java Client 3.4.1. Need to delete Default value in the Email Field(Textbox) and Enter new value.

No issues with Appium 1.5.3 on macbook for Android

On Oct 12, 2016 2:00 PM, "abvijay" [email protected] wrote:

I dont see SendKeyEvent or pressKeyCode in appiumdriver instance. Using
AppiumForWindows 1_4_13_1. Java Client 3.4.1. Need to delete Default value
in the Email Field(Textbox) and Enter new value.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/appium/appium/issues/4297#issuecomment-253151390, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AJ9u361J5UXsDBKIPU1AP1wRJsscbOqrks5qzJqqgaJpZM4DLNq5
.

@Nischalapp How to install Appium 1.5.3. Could you please provide link for installation procedure. I have installed AppiumForWindows 1_4_13_1 but Appium 1.5.3.dmg looks different.

Ya so it's for Mac OS and if u have Mac then just download appium 1.5.3 and
double click n install

On Oct 12, 2016 6:48 PM, "abvijay" [email protected] wrote:

@Nischalapp https://github.com/Nischalapp How to install Appium 1.5.3.
Could you please provide link for installation procedure. I have installed
AppiumForWindows 1_4_13_1 but _Appium 1.5.3.dmg_ looks different.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/appium/appium/issues/4297#issuecomment-253207432, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AJ9u3wgCibbyg31shPw5O1IX3v75nMJEks5qzNrtgaJpZM4DLNq5
.

@Nischalapp I am Using windows 8 os(PC) and running scripts for Android. Which version of appium should I use to get SendKeyEvent or pressKeyCode methods?

Appium on windows is not gud at all. But ya u can chk with latest version
on appium site

On 13-Oct-2016 11:32 AM, "abvijay" notifications@github.com wrote:

@Nischalapp https://github.com/Nischalapp I am Using windows 8 os(PC)
and running scripts for Android. Which version of appium should I use to
get SendKeyEvent or pressKeyCode methods?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/appium/appium/issues/4297#issuecomment-253421801, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AJ9u3_Q_L-YAGVBYRkZBK6sGaYT-9RHCks5qzclbgaJpZM4DLNq5
.

@congthang1 I tried, but it doesn't work. I am using appium_lib

How are you sending text to android using appium? adb does work in sending a string but doesn't when I want to send some randomly generated string from a variable.

try using set_text("[email protected]") or uninstall current selenium install selenium==3.3.1(both case it worked for me)

@JasonDobo answer deserves a big credit. I have been on the issue for over 2 weeks trying to solve the problem. I have tried all the suggestions online, including adb, nothing worked until I tried his suggestion. It worked perfectly.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings