I'm trying to type some text inside an EditText:
public void testSearch() {
onView(withId(R.id.titleInput)).perform(typeText("Engineer"));
onView(withId(R.id.titleInput)).check(matches(withText("Engineer")));
}
I see the EditText is getting focus, but nothing happens. No text is typed.
I tried this on a phone and an emulator - same result.
Looks like I figured out the issue. It had to do with hardware vs software keyboard.
For Emulators:
Go to Settings -> Language & Input -> switch the Default Input to Sample Soft Keyboard.
For Phones:
Install a software keyboard from the Play store and switch to it. It appears that the native keyboards of some phones do not work.
It works now.
Had the same issue using Espresso 2. As a workaround I'm using replaceText instead of typeText.
public void testSearch() {
onView(withId(R.id.titleInput)).perform(click(), replaceText("Engineer"));
onView(withId(R.id.titleInput)).check(matches(withText("Engineer")));
}
If the EditText does not has the focus yet, you should click on it first. If this solves your problem, then there is no bug.
onView(withId(R.id.titleInput)).perform(click()).perform(typeText("Engineer"));
You can bypass the problem by calling setText on the EditText.
final EditText titleInput = (EditText) activity.findViewById(R.id.titleInput);
getInstrumentation().runOnMainSync(new Runnable() {
public void run() {
titleInput.setText("Engineer");
}
});
Same issue resolved with the following:
editText.perform(scrollTo(), click(), clearText(), typeText(myInput), closeSoftKeyboard())
Interestingly, I only ever had a problem when my machine was working hard.
You can include it with in the code like this,
onView(withId(R.id.titleInput))
.perform(click(), replaceText("Engineer"), closeSoftKeyboard());
I fixed this issue by setting layout_height="wrap_content" on the View I wanted to click(). Maybe it can help someone here.
If you're using Genymotion, you may need to switch the default keyboard in Genymotion Configuration (it's an app on the emulator).
Go to Apps -> Genymotion Configuration -> Keyboard -> Virtual keyboard (click "Yes" when you're prompted to reboot)
NOTE: These changes do not persist after you close the emulator. You will need to set this every time you start the emulator.
for me I was annotated my test method with #UiThreadTest. I removed that and it solved.
Adding closeSoftKeyboard() after typeText() worked for me.
CODE:
onView(withId(R.id.editTextUserInput))
.perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard());
This is how it is documented in the Android docs.
Related
Question in the title.
I tried something like:
onView(withId(R.id.search_edit_text))
.perform(typeText("some"), pressKey(KeyEvent.KEYCODE_ENTER));
But it doesn't work. Keyboard is still shown and TextView.OnEditorActionListener not called. Any ideas?
Try
onView(withId(R.id.search_edit_text))
.perform(typeText("some"), pressImeActionButton());
I used KEYCODE_BACK and it works well. KEYCODE_ENTER not working on my device SAMSUNG A70
onView(withId(R.id.edit_text).perform(ViewActions.pressKey(KeyEvent.KEYCODE_BACK))
In my app, I have an EditText, with a button to change the keyboard input type. The code:
ToggleCambiarTeclado.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
if (ToggleCambiarTeclado.isChecked()) {
tipoDeTecladoActual = InputType.TYPE_CLASS_NUMBER;
imagenTeclado.setImageDrawable(getResources().getDrawable(R.drawable.keyboard_numeric));
} else {
tipoDeTecladoActual = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
imagenTeclado.setImageDrawable(getResources().getDrawable(R.drawable.keyboard_querty));
}
editNumeroContador.setInputType(tipoDeTecladoActual);
}
});
It works perfectly in my phone...but my boss has a Samsung, and is not changing the keyboard type in his phone.
I have tried changing it to TYPE_TEXT_VARIATION_NORMAL, TYPE_TEXT_VARIATION_VISIBLE_PASSWORD and YPE_CLASS_TEXT, neither of them are working.
Anyone knows if this is a bug? Any known workaround?
Thank you.
EDIT:
Just realized my boss has TouchPal installed. If he changes the default keyboard to the standard it works perfectly...
Later Samsung devices have SwiftKey keyboards built in. SwiftKey intentionally decided at some point to ignore Android's InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS.
A workaround is to use InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD, which is somewhat hacky, but an unfortunately common workaround.
XML variant: android:inputType="textVisiblePassword"
Samsung's behave weirdly with most things. I've had this issue before and I seem to recall that changing the input type to email worked like a charm. Give it a try.
how to clear text edit field? android python appium?
I tried that way:
el = driver.find_element_by_id('text edit field id').clear()
el.click()
el.clear()
however, it actually deletes only one symbol.
I think may by call an el.click() twice and send keycode to delete highlighted text area but how to highlight the text?
Interestingly, such problem reproduces in Sony Xperia z3 compact, android 5.0.1.
In lg, nexus android 4.4,5.1 accordingly, the above code works well
i had faced same issue with my android application but i am doing automation in java , so for the solution i am performing tap Action twice near the location of the element so it will select all the text which already written in text field and after that click on that "cut" symbol so it will clear text field.
i have written a method for sendkeys in android device.
public void typeForAndroid(AppiumDriver appiumDriver,WebElement ele,String text)
{
if(ele.getText().isEmpty())
{
ele.sendKeys(text);
}
else
{
TouchAction action=new TouchAction(appiumDriver);
action.tap(ele.getLocation().getX()+5, ele.getLocation().getY()+5);
action.tap(ele.getLocation().getX()+5, ele.getLocation().getY()+5);
appiumDriver.performTouchAction(action);
pause(2);
try{
appiumDriver.findElementById("android:id/cut").click();
}
catch(Exception e)
{
appiumDriver.sendKeyEvent(67);
}
pause(2);
ele.sendKeys(text);
}
}
this is working for me. I hope this might works for you.
in this i have used appiumdriver but you can also use androiddriver.
Thanks
When I write into a line edit using the Android keyboard, and I press the "Done" button (screenshot below), the keyboard does not disappear. This happens even in a newly created project with just a line edit (I tested it).
How can I make "Done" to hide the keyboard?
Please note that I am looking for a developer solution (i.e. programming, not user oriented) and a native way (i.e. C++/Qt, not Java).
I'm using Qt 5.2.0.
You have to call the QInputMethod::hide() slot.
C++ Solution
connect(ui->lineEdit, SIGNAL(editingFinished()), QGuiApplication::inputMethod(), SLOT(hide()));
QML Solution
TextInput {
Keys.onEnterPressed: {
//...
Qt.inputMethod.hide()
}
Keys.onReturnPressed: {
//...
Qt.inputMethod.hide()
}
}
I have a small phonegap application with jquery mobile and backbone.
I'm trying to show popup to user by manually calling .popup() method.
Everything works fine on iOS but on android I got strange issue: popup is showing for few moments and than disappear.
Here the actual code:
var PostView = Backbone.View.extend({
events: {
'touchend .add-comment-button': 'addComment'
},
addComment: function() {
this.$(".comment-popup").popup('open', { history: false });
return false; // Stop bubbling.
}
});
I'm using history: false because this popup is actualy part of subpage.
The code looks very simple, I'm just can't understand why it can disappear, and why this happen only on android devices.
Thanks, and sorry for my bad english.
I spent hours trying to fix this problem.
Finally I ended up doing the following two things that seemed to fix the problem.
1 - Use the uncompressed jqm file. i.e jquery.mobile.1.2.0.js
2 - I was triggering the popup programatically using the 'tap' option - once changed to the 'click' option it worked.
$('.option').live('click', function() {
$('#popup-div').popup('open');
});
I spent hours trying to fix this problem.
Finally I ended up doing the following two things that seemed to fix the problem.
this code snippet may help you ->
$('#testBtn').on('tap',function(e){
console.log("button clicked");
e.preventDefault();
$('#testPOPUP').popup("open");
});
Please note i have used e.perventDefault().
I didn't feel like changing my .tap() events to the click event and I didn't have a case where I could use preventDefault()so I just added a timeout to the popup('open') line. My hoverdelay in jqm is set to 150 so I set this timeout to 600 just to be on the safe side. Works fine, doesn't feel sluggish for the user.
One way to 'fix' it is by setting data-history="false" on the popup div
See also this question
JQuery Mobile popup with history=false autocloses
I have the exact same problem when trying to use popup('open') on an android 2.3 device (both in native browser and in firefox) and it works just fine on browsers on other devices. I'm also using backbone event management to open my popup (used the tap event and no aditionnal options to popup).
What I did to 'correct' the problem is that I removed the backbone event management for this event and added a listener in the render function. In your case this would look something like this :
events: {
// 'touchend .add-comment-button': 'addComment'
},
render: function() {
$(this.el).html(this.template(this.model));
$(this.el).find('.add-comment-button').tap(function(el){
this.addComment(el);
return false;
}.bind(this));
}
I have no idea where the problem comes from (must be some incompatibility between backbone and jquery mobile) and why we only see it on android but for the moment with this workaround my app seems to work fine on any device.
Edit: oops, it turns out that in my case the problem was I was missing "return false;" in the function dealing with the event.
Now that I added it, it works correctly with the backbone event management.
Sadly that doesn't explain why you have the issue and why I was seeing it only on android.
In case it helps anyone, I had the same problem occurring with Bing Maps, with the Microsoft.Maps.Events.addHandler(pin, 'click', callback) method.
Not particularly nice, but instead I stored an ID in pushpin._id and did the following:
$("#page").on('vclick', function (event) {
if (event.target.parentElement.className === "MapPushpinBase") {
$("#stopPopup").popup('open');
}
});
One brute force option is to check whether popup was hidden and reopen it.
In a loop, because the exact time the popup becomes hidden seems to be varied.
var hidden = $('#' + id + '-popup') .hasClass ('ui-popup-hidden')
if (hidden) $('#' + id) .popup ('open')
A working example: http://jsfiddle.net/ArtemGr/hgbdv9s7/
Another option could be to bind to popupafterclose:
var reopener = function() {$('#' + id) .popup ('open')}
$('#' + id) .on ('popupafterclose', reopener)
$('#' + id) .popup ('open')
Like here: http://jsfiddle.net/ArtemGr/gmpczrdm/
But for some reason the popupafterclose binding fails to fire on iPhone 4 half of the time.