Handling of list of edit-text in single screen using By.classname

I have list of edittext in single screen and I used the following code snippet for locating and sending the values to edittext.
List edit_text = driver.findElements(By.className(“android.widget.EditText”));
edit_text.get(0).sendKeys(“xxxx”);
edit_text.get(1).sendKeys(“1234”);
The above is working fine .

I need to change the above code by using By.classname.

File1.java
List edit_text = (List) By.className(“android.widget.EditText”);
public void driver_mobile(){
driver.findElementsByClassName(edit_text);
}

File2.java:
Need to call the driver_mobile() method in this file for different index of edit_text.
File1 obj= new File1(driver)
obj.driver_mobile().edit_text(0).sendKeys(“xxxx”);
obj.driver_mobile().edit_text(1).sendKeys(“1234”);

The error is showing in the file2 snippet and in file 1 driver.findElementsByClassName(edit_text); line. I dont know how to use this properly. Can anyone say how to proceed with this?

Hi @Durga_M,

I’m not sure I’m clear on what you are going to do. So try below adjustment.

File1.java

public List driver_mobile(List edit_text){
List edit_text = driver.findElements(By.className(“android.widget.EditText”));
return edit_text;
}

File2.java:
File1 obj= new File1(driver);
List edit_text = obj.driver_mobile();
edit_text.get(0).sendKeys(“xxxx”);
edit_text.get(1).sendKeys(“1234”);

1 Like

Thanks a lot … i tried it and it worked for me now.

Happy when hearing that you got what you want.
From that simple code, you can implement by your way later.