Elements are not changing :

119 views
Skip to first unread message

Pamodha

unread,
Apr 23, 2014, 4:25:37 PM4/23/14
to appium-...@googlegroups.com

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 

Jonah Stiennon

unread,
Apr 23, 2014, 6:55:13 PM4/23/14
to appium-...@googlegroups.com
Hi Pamodha,

Maybe the elements you are getting with xpath aren't the correct elements. Try to following:


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.

Jonah Stiennon

unread,
Apr 23, 2014, 6:55:48 PM4/23/14
to appium-...@googlegroups.com
Also, I assumed it was Android. Are you using iOS?

Pamodha

unread,
Apr 24, 2014, 3:12:58 PM4/24/14
to appium-...@googlegroups.com

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']"));

assert(password.getText().equals("Enter Your Password"));

password.sendKeys("test2");


Jonah Stiennon

unread,
Apr 25, 2014, 5:55:28 PM4/25/14
to appium-...@googlegroups.com
Pamodha,

I took a closer look. I made an app with three text fields, and ran the following:

List<WebElement> textfields = driver.findElementsByClassName("android.widget.EditText");
    WebElement school = textfields.get(0);
    WebElement username = textfields.get(1);
    WebElement password = textfields.get(2);

    school.sendKeys("sample");
    username.sendKeys("test1");
    password.sendKeys("test2");

And it worked:


I'm going to have to ask you to try more experimentation to figure out your issue.
Try making you case simpler and simpler until it works.
Try different locator strategies besides xpath, or try simplifying your layout.

Please report what you find, in case you reveal a bug in appium.

Thanks for you sorry, sorry I couldn't figure it out ;)

On Wednesday, April 23, 2014 1:25:37 PM UTC-7, Pamodha wrote:
Message has been deleted
Message has been deleted

Rameshwar Juptimath

unread,
Apr 28, 2014, 1:07:14 PM4/28/14
to appium-...@googlegroups.com
Hi Pamodha,

Try this code:

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");

Jonah Stiennon

unread,
Apr 28, 2014, 3:35:26 PM4/28/14
to appium-...@googlegroups.com
Pamodha,

I'm glad you figured it out :) I didn't notice that the first input was a searching list box. Now it makes sense why we saw the behavior you did.

This will be useful for other people who are testing. I guess you have to click the Android list box before you can begin sending keys to a different input.
Reply all
Reply to author
Forward
0 new messages