Android Appium : Not able enter the text in textbox - android

//For log in scenario, I just want to enter the userID and password. I tried with different Xpath but still it's not able to identify the box. every-time getting an no such element exception. We are using testNG.
#AndroidFindBy(xpath = "XYZ")
public MobileElement txtUserName;
utils.EnterText(UserNameorMailId,txtUserName);
Different Xpath tried: xyz is placeholder.
//*[#id='username']
//*[#text='Edit Text ; Email Address or Username']
//*[#id='layout_usename']//*[#text='Edit Text ; Email Address or Username']
Error message:
Method threw 'org.openqa.selenium.NoSuchElementException' exception. Cannot evaluate io.appium.java_client.android.AndroidElement$$EnhancerByCGLIB$$34efbdcd.toString()
I am not sure what else I should try and what exactly the issue is...Help is really appreciated ..

What's the exact error you are getting while entering text ? In case you are able to find the element Can you try to use ".//*[#text='Email Address or Username']"

Can you try using AndroidElement instead of MobileElement?
From the docs, I can see that MobileElement is an abstract class which is inherited by AndroidElement class, so using an object of an Abstract class may not work.
MobileElement:
https://appium.github.io/java-client/io/appium/java_client/MobileElement.html
AndroidElement:
https://appium.github.io/java-client/io/appium/java_client/android/AndroidElement.html

Does clicking on the textbox produce the same error? Have you try setValue instead?

Related

empty EditText caused by wrong view?

I'm new to android studio and programming. I create second table to my database and have almost identical onClickListener class first one work perfect but second give me error. EditText .getText().toString() is empty so I can't convert it to dobule. I think this problem may be caused by View but I dont know java that well and I cant find solution.
EDIT: I manage to solve this problem by adding AlertDialog to my second OnClick listener. This is not exactly what I want but it works.
Could you try setting the input type on the edittext as numberDecimal
android:inputType="numberDecimal"
That way, the user will have to input decimal number always if thats what you are expecting the user to enter.
Also, you could do a null check
if(stringWzrost != null && !stringWzrost.trim().equals("")) {
bmiWzrost = Double.valueOf(stringWzrost);
}
Right now I see that its commented out.

While automating login process with appium the password and username are entred in the same field of username

Although the test is clear and simple i'm always facing the same problem while tring to send keys (username; password) the password field is written in place of username !
Here my Test NG i'm using appium for my tests
#Test
public void Test1() throws InterruptedException {
System.out.println("newlook-tutoriel");
driver.findElement(By.id("skip")).click();
System.out.println("newlook-welcome");
driver.findElement(By.id("btn_signin_welcome")).click();
System.out.println("newlook-Me connecter");
driver.findElement(By.id("input_email")).sendKeys("e#e.emma.com");
driver.findElement(By.id("input_password")).sendKeys("00000000");
System.out.println("connected !!!!");
}
i got username = e#e.emma.com00000000
This is strange issue. But Here is the solution for this.
public void hideKeyBoard()
{
try{driver.hideKeyboard();}
catch(Exception e){}
}
Use above method to hide keyboard
driver.findElement(By.id("input_email")).click();
driver.getKeyboard().sendKeys("e#e.emma.com");
hideKeyboard();
driver.findElement(By.id("input_password")).click();
hideKeyboard();
driver.getKeyboard().sendKeys("00000000");
Hope this helps :)
This could be timing issue, just for test try to put Thread.sleep(5000); after you set username and before you try to set password and see what happens.
It is strange but it happend in my case, sometimes my firefoxdriver wrote in wrong field even if all fields were unique and successfully found. Small time span between two sendKeys() calls solved the issue. I wasn't using sleeps, simple verification if correct text was written in the field between these 2 calls was enough time so that next sendKeys() writes in correct field.
Finally i have resolved this issue by adding to my code :
driver.hideKeyboard();
The issue was because the keyboard is hiding the field of password !

Xamarin: Setting text for a TextView programmatically

This is probably a mistake or lack of comprehension on my part, but I am quite confused right now. I'm trying to set a TextView in my Xamarin Android application programmatically. Here's my code:
TextView currentCharacterName =
FindViewById(Resource.Id.characterName);
currentCharacterName.SetText("test");
Unfortunately, this does not work, as I get the error "Argument 1: cannot convert from 'string' to 'int'". After reading in the available methods for SetText, I noticed the method I'm trying to call demands a ResId. I don't really understand why I would need a ResId to modify the text of a TextView.
I tried searching on Google for answers, and I came across this answer from 2014 that had the exact same problem as I do. The solution was to use the Text() method instead to set the TextView. Unfortunately, when I try this solution, I get the error "Non-invocable member 'TextView.Text' cannot be used like a method". When I try to check the Text method description, I see "string TextView {get/set} To be added."
Does this mean there's no implementation yet to set the text of a TextView? I am really reluctant to believe this, as it baffles me that such a big framework like Xamarin wouldn't even have get/set functions for something as simple as setting the text of TextView. I feel like there's a very simple solution for my problem, but I can't seem to find it.
TextView.SetText(X) allows you to set the text from a Resource id:
currentCharacterName.SetText(Resources.Id.MyString);
You are looking for the Text property:
currentCharacterName.Text = "test";
Xamarin: TextView class
Android.Widget.TextView.Text Property
Syntax:
public String Text { get; set; }
Test this code:
TextView currentCharacterName = FindViewById<TextView>(Resource.Id.characterName);
currentCharacterName.Text = "Your Text";

Android - EditText setError not showing until EditText is blurred and focused again

Hello,
I'm implementing a Login activity for my application. I make a server request so as to know if the user/password is correct. If not, I would like to show an error on the Password EditText.
My code for that is the following:
public void onLoginError() {
inPassword.setError("Error...");
}
This function is called when the request returns an invalid user/password result.
The problem is that the error is not shown until I deselect the Password EditText and focus it again.
Why is this happening? Do I have to update renderer or something like that because it is an Async behavior?
Thanks in advance.!
You should give focus to your EditText:
inPassword.requestFocus();
inPassword.setError("Error...");
or:
inPassword.setError("Error...");
inPassword.requestFocus();
I am using JDeferred and there is a module for android that uses the UI thread so as to change view.

Updating an EditText with Espresso

I'm attempting to update an EditText as part of an Espresso test with:
onView(allOf(withClassName(endsWith("EditText")), withText(is("Test")))).perform(clearText())
.perform(click())
.perform(typeText("Another test"));
However I receive the following error:
com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException: No views in hierarchy found matching: (with class name: a string ending with "EditText" and with text: is "Test")
By breaking down the test line I can see that this occurs after performing clearText(), so I assume that the matchers are being re-run prior to each perform and fail the prior to the second action. Although this makes sense, it leaves me somewhat confused as to how to update the EditText using Espresso. How should I do this?
Note that I cannot use a resource ID or similar in this scenario and have to use the combination as shown above to identify the correct view.
You can use the replaceText method.
onView(allOf(withClassName(endsWith("EditText")), withText(is("Test"))))
.perform(replaceText("Another test"));
Three things to try:
1. You can run performs in succession.
onView(...)
.perform(clearText(), typeText("Some Text"));
2. There is a recorded issue on the Espresso page which was marked as invalid (but is still very much a bug). A workaround for this is to pause the test in-between performs.
public void test01(){
onView(...).perform(clearText(), typeText("Some Text"));
pauseTestFor(500);
onView(...).perform(clearText(), typeText("Some Text"));
}
private void pauseTestFor(long milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
3. Are you absolutely sure that your EditText contains the text, "Test"?
To set value in EditText with Espresso
simple like this
onView(withId(R.id.yourIdEditText)).perform(typeText("Your Text"))
I was having a similar issue and solved it using the containsString matcher and Class.getSimpleName(). Like this:
onView(withClassName(containsString(PDFViewPagerIVZoom.class.getSimpleName()))).check(matches(isDisplayed()));
You can see the full code here
You could try two things. First I would try to use
onView(withId(<id>).perform...
This way you would always have access to the EditText field even when other EditText fields are on the screen.
If that's not an option, you could split up your perform calls.
onView(allOf(withClassName(endsWith("EditText")),withText(is("Test")))).perform(clearText());
onView(withClassName(endsWith("EditText"))).perform(click());
onView(withClassName(endsWith("EditText"))).perform(typeText("Another Test");

Categories

Resources