NOT able to enter sendkey in second text field

There is a login screen as showed below. I used code below and able to enter data in the first email address and as the softkey comes, I tried hiding key, hide worked. The issue is the data is not getting enter in the second text field.

Tried gooling to get the code to click on NEXT button on the keyboard that may solve the problem, Invain I was not able to find it out.

I’m new to this appium testing.

Code:
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By
.xpath("//android.widget.Button[contains(@text, ‘SIGN UP’)]")));

	List<AndroidElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
	textFieldsList.get(0).sendKeys("[email protected]");
	driver.hideKeyboard();
	
	 wait = new WebDriverWait(driver, 50);
	 wait.until(ExpectedConditions.elementToBeClickable(By
	        .xpath("//android.widget.Button[contains(@text, 'Log in')]")));
	    	    	
	textFieldsList.get(2).sendKeys("Passw0rd");
	driver.hideKeyboard();

Please advice me, how to handle this situation

ERROR : java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at Package.eMaintenance.play(eMaintenance.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

textFieldsList.get(2).sendKeys("Passw0rd");

You have 2 fields, so its get(0) and get(1) for the second. It says so in the error.

I tried still got this error, both email and password got entered in the same field “Email”

Sorry if you see in the UIautomator, the get(1) is for View and get(2) is for edittext.

Please find the screen shot.

As @Telmo_Cardoso said you are fetching the wrong element here. There are only two text field in the current screen and find by element returns two text field. It’s not getting the “View” element because it’s class is not editText. So you have only 2 elements in your list and you are trying to access the third element, which does not exists. So index 1 which is second item on the list.

textFieldsList.get(1).sendKeys("Passw0rd");

AS I commented before, I tried textFieldsList.get(1).sendKeys(“Passw0rd”);,However the email and password data got entered in the same field “Email”.

ERROR:

java.lang.IndexOutOfBoundsException: Index: 2, Size: 2

I solved this issue …Thanks

You should put how you solved it. Otherwise, in the future someone will search this thread for the same issue and find this thread with no answer.

1 Like

Yeah… @preethi ,

Great work done…!!! But could you please let us know what you’ve done to solve the issue.This may help others too.!!
@wreed :+1:

After the first field data gets entered, keyboard was over lapping the next fields. After changing the get(1) still second field data was getting entered to first field (Wired), so I use hide keyboard after first operation and that solved the problem for me to enter the data into second field.

WebDriverWait wait = new WebDriverWait(driver, 30000);
wait.until(ExpectedConditions.elementToBeClickable(By
.xpath("//android.widget.Button[contains(@text, ‘Log in’)]")));

	List<AndroidElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
	textFieldsList.get(0).sendKeys("bxdxdfdsf");
	
	//Hide the Keyboard
	driver.hideKeyboard();
	
	//Entered the Password
	textFieldsList.get(1).sendKeys("afasfasf");
	
	//Hide the Keyboard    	
	driver.hideKeyboard();
1 Like