I am new to appium automation and currently I’m using appium to automate testing for android native app. I have setup everything and run the test using (selenium) Java.
I’m facing some issues when trying to fill the input text field in a login screen. I’m using text field element by By.xpath.
WebElement school =driver.findElement(By.xpath("//EditText[@text='Search for your School']"));
school.sendKeys("simple");Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
WebElement username =driver.findElement(By.xpath("//EditText[@text='Enter Your Username']"));Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
username.sendKeys("test1");
WebElement password =driver.findElement(By.xpath("//EditText[@text='Enter Your Password']"));
password.sendKeys("test2");
Here in this login screen there is an extra field apart
from username and password which has to search a value from service and once user
select the value its filed the text field. See the attach pic below.Â
After I execute the test it’s identifying the first
element and set the value send as "simple" in the first text field. But the
problem is when its coming for second element (username) and its still update
the same text field. See the attach pic below.Â
please help me to figure this out.Â
Thanks in Advance, pamodhaÂ
WebElement school =driver.findElement(By.xpath("//EditText[@text='Search for your School']"));
assert(school.getText().equals("Search for your School")); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
WebElement username =driver.findElement(By.xpath("//EditText[@text='Enter Your Username']"));Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
assert(username.getText().equals("Enter Your Username"));
WebElement password =driver.findElement(By.xpath("//EditText[@text='Enter Your Password']"));
assert(password.getText().equals("Enter Your Password"));
That should prove that at least part of this is working.
Also try:
assert(school.getClass().equals("android.widget.editText"));
assert(username.getClass().equals("android.widget.editText"));
assert(password.getClass().equals("android.widget.editText"));
Try those assertions. If any fail, then you aren't really getting the elements you want to be editing.
If they all pass, post here and we can try to help more.
Hi Jonah,
Thanks for your quick respond. Yes I am using android.
I checked the above code and it’s worked half.  I believe elements which getting with xpath is correct. It has identified the elements (username & password) perfectly when I committed the first element (select school) in code.
I think the issue is in first element when it searches the value from searching list box and after that it’s unable to identify/move to next element. I have tried putting Thread.sleep(); to wait until identify the next element. but that also didn't work.
Please see the screen print after used code.
WebElement school =driver.findElement(By.xpath("//EditText[@text='Search for your School']"));
assert(school.getText().equals("Search for your School")); Â Â Â Â Â Â Â
school.sendKeys("simple");Â Â Â Â
Thread.sleep(1000); Â Â Â Â Â Â Â Â
                        Â
WebElement username =driver.findElement(By.xpath("//EditText[@text='Enter Your Username']"));Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
assert(username.getText().equals("Enter Your Username"));
username.sendKeys("test1");
Â
WebElement password =driver.findElement(By.xpath("//EditText[@text='Enter Your Password']"));
WebElement school =driver.findElement(By.xpath("//EditText[contains(@text,'Search for your School')]"));
school.sendKeys("simple");Â
Thread.SLeep(5000); Â Â Â Â Â
WebElement username =driver.findElement(By.xpath("//EditText[contains(@text,'Enter Your Username')]"));Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
username.sendKeys("test1");
Thread.SLeep(5000);
WebElement password =driver.findElement(By.xpath("//EditText[contains(@text='Enter Your Password')]"));
password.sendKeys("test2");