How to enter 6 digit code in the element

iiiiiiiiiii stop using xPath. it just nightmare in support.
try something like:

        List<WebElement> inputList = driver.findElements(AppiumBy.className("android.widget.EditText"));
        // set email
        inputList.get(0).sendKeys("[email protected]");
        // set pin
        inputList.get(1).sendKeys("my_pin");
2 Likes

it worked like a charm @Aleksei. l will do my best to stay away from xpath.
l have a question again. My app has a face match functionality. Using appium how can l automate this face match feature

Love you bro…you are awesome

@Aleksei l am getting index out of bounds error

		List<WebElement> inputList = driver.findElements(AppiumBy.className("android.widget.EditText"));
		inputList.get(0).click();
		inputList.get(0).sendKeys("[email protected]");
		inputList.get(1).click();
		inputList.get(1).sendKeys("22271677774");
		inputList.get(2).click();
		inputList.get(2).sendKeys("34299589242");
		inputList.get(3).click();
		inputList.get(3).sendKeys("Chemistry@22");
		
		driver.hideKeyboard();

FindElement is fast action. Possibly it searches while not all elements appeared. Try add pause to check before find input elements.

l am using a thread.sleep method. See the complete code l am running below

@Test()
	public void RegisterAgent() throws SQLException, InterruptedException {
	
		
		driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.EditText")).click();
		driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.EditText")).sendKeys("07068181972");
		driver.findElement(AppiumBy.accessibilityId("Continue")).click();
		Thread.sleep(15000);
		
		Database db = new Database("v3_Authentication");
		String otp = db.getAgentOtp(phoneNumber);
		db.closeDbConnection();
		
		new Actions(driver).sendKeys(otp).perform();
		//driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View/android.view.View/android.view.View[2]")).sendKeys("345235");
		//driver.executeScript("mobile: type", ImmutableMap.of("text", "234567"));
		//driver.hideKeyboard();
		driver.findElement(AppiumBy.accessibilityId("Continue")).click();
		Thread.sleep(5000);
	
		List<WebElement> inputList = driver.findElements(AppiumBy.className("android.widget.EditText"));
		inputList.get(0).click();
		inputList.get(0).sendKeys("[email protected]");
		inputList.get(1).click();
		inputList.get(1).sendKeys("22271677774");
		inputList.get(2).click();
		inputList.get(2).sendKeys("34299589242");
		inputList.get(3).click();
		inputList.get(3).sendKeys("Chemistry@22");
		
	
		
		driver.hideKeyboard();
		driver.findElement(AppiumBy.className("android.widget.Button")).click();
	
		//driver.findElement(By.xpath("//android.widget.Button[@content-desc='Continue']")).click();
		
		Thread.sleep(5000);
	}

It does not find last? I see last one is password. Often it has another class name

l dont understand @Aleksei

Expand it field in Appium inspector -> image

l can see the password field has an inner android.view.view. Is that what you mean. How do l now update my code to handle this

so you can click on it but sendText fails?

l dont understand. l updated my code

@Test()
	public void RegisterAgent() throws SQLException, InterruptedException {
	
		
		driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.EditText")).click();
		driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View/android.view.View/android.widget.EditText")).sendKeys("07068181972");
		driver.findElement(AppiumBy.accessibilityId("Continue")).click();
		Thread.sleep(15000);
		
		Database db = new Database("v3_Authentication");
		String otp = db.getAgentOtp(phoneNumber);
		db.closeDbConnection();
		
		new Actions(driver).sendKeys(otp).perform();
		//driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View/android.view.View/android.view.View[2]")).sendKeys("345235");
		//driver.executeScript("mobile: type", ImmutableMap.of("text", "234567"));
		//driver.hideKeyboard();
		driver.findElement(AppiumBy.accessibilityId("Continue")).click();
		Thread.sleep(5000);
	
		List<WebElement> inputList = driver.findElements(AppiumBy.className("android.widget.EditText"));
		//System.out.println(inputList);
		//System.out.println(inputList.size());
		
		inputList.get(1).click();
		inputList.get(1).sendKeys("[email protected]");
		inputList.get(2).click();
		inputList.get(2).sendKeys("22271677774");
		inputList.get(3).click();
		inputList.get(3).sendKeys("34299589242");
		inputList.get(4).click();
		inputList.get(4).sendKeys("Chemistry@22");
		
		Thread.sleep(7000);
		
		driver.hideKeyboard();
		//driver.findElement(AppiumBy.className("android.widget.Button")).click();
	
		//driver.findElement(By.xpath("//android.widget.Button[@content-desc='Continue']")).click();
		
		Thread.sleep(5000);
	}

Error message is

[RemoteTestNG] detected TestNG version 7.6.1

SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
e[35m[Appium]e[39m Welcome to Appium v2.0.0-beta.42
e[35m[Appium]e[39m Non-default server args:
e[35m[Appium]e[39m { address: e[32m’127.0.0.1’e[39m }
e[35m[Appium]e[39m Attempting to load driver uiautomator2…
[debug] e[35m[Appium]e[39m Requiring driver at C:\Users\mataga.appium\node_modules\appium-uiautomator2-driver
e[35m[Appium]e[39m Attempting to load driver flutter…
[debug] e[35m[Appium]e[39m Requiring driver at C:\Users\mataga.appium\node_modules\appium-flutter-driver
e[35m[Appium]e[39m Appium REST http interface listener started on 127.0.0.1:4723
e[35m[Appium]e[39m Available drivers:
e[35m[Appium]e[39m - [email protected] (automationName ‘UiAutomator2’)
e[35m[Appium]e[39m - [email protected] (automationName ‘Flutter’)
e[35m[Appium]e[39m No plugins have been installed. Use the “appium plugin” command to install the one(s) you want to use.
626130
FAILED: agent.AgentRegistrationTest.RegisterAgent
java.lang.IndexOutOfBoundsException: Index 4 out of bounds for length 4
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:372)
at java.base/java.util.ArrayList.get(ArrayList.java:459)
at agent.AgentRegistrationTest.RegisterAgent(AgentRegistrationTest.java:82)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:677)
at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221)
at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50)
at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:962)
at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194)
at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.testng.TestRunner.privateRun(TestRunner.java:806)
at org.testng.TestRunner.run(TestRunner.java:601)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:433)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:427)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:387)
at org.testng.SuiteRunner.run(SuiteRunner.java:330)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
at org.testng.TestNG.runSuites(TestNG.java:1099)
at org.testng.TestNG.run(TestNG.java:1067)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0

===============================================
Default suite
Total tests run: 1, Passes: 0, Failures: 1, Skips: 0

it should start from get(0) !!! 0 is first element

1 Like

it works now. but the next step is facematch.Do you know how to handle this

this is not faceID but custom implementation of your app. ask developers to make ability to skip it or accept any picture. Try continue your test as is and when you stop ask developers for help.

it can accept a picture but how to pass that picture in my code is what l dont know how to right now

I do not know any way replace image of real camera…

1 Like

@Aleksei how do l automate an android app written with flutter

I never used. Cant help.

1 Like

Please https://discord.gg/DK3x8fvj join here and let’s help each other.