How to enter 6 digit code in the element


l am locating the element using the below xpath
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("728192");

my tests is not failing but its not entering the values in the element circled on the left.
Kindly assist

This is custom view in your app. Not input field. So make keyboard visible and use it (same as user).

1 Like

@Aleksei thanks for the response. l am pretty new to appium so please pardon me if l sound naive. so l am getting the OTP from the DB and saved in a variable called OTP like in the code below
Database db = new Database(“v3_Authentication”);
String otp = db.getAgentOtp(phoneNumber);
db.closeDbConnection();
How do l enter this value using the keyboard

same as user. try first tap on any circle to force keyboard to appear.


The is the first screen l see on navigating to this page. As you can see the keyboard shows and the cursor is in the first circle.

no try simple:

driver.executeScript("mobile: type", ImmutableMap.of("text", your_6_numbers));

-> https://github.com/appium/appium-uiautomator2-driver#mobile-type

PS also needed add --relaxed-security flag to appium server
https://appium.io/docs/en/writing-running-appium/security/

@Aleksei still not working… see my complete test method 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("08150367435");
	Thread.sleep(1000);
	driver.findElement(AppiumBy.accessibilityId("Continue")).click();
	Thread.sleep(10000);

	Database db = new Database("v3_Authentication");
	String otp = db.getAgentOtp(phoneNumber);
	db.closeDbConnection();
	
	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]")).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.view.View[2]")).sendKeys("3");
	driver.executeScript("mobile: type", ImmutableMap.of("text", otp));

	//System.out.println(content);
	//driver.findElement(By.xpath("//android.view.View[@longClickable='true'")).sendKeys("1");
	Thread.sleep(3000);
	driver.hideKeyboard();
	driver.findElement(AppiumBy.accessibilityId("Continue"));
	Thread.sleep(2000);
}
  1. what happens?
  2. add appium logs in DEBUG mode as link to https://gist.github.com/
  3. as last try you can still use ADB commands for Android -> https://stackoverflow.com/questions/7789826/adb-shell-input-events
[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.
868821
PASSED: agent.AgentRegistrationTest.RegisterAgent

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

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

this is not Appium logs in DEBUG level

Oh…l will research how to get that now. but is my test method suppose to work.Kindly endure, like l said, l am new to appium.

your appium server should start with:

appium --log-level debug --relaxed-security
[Appium] Welcome to Appium v2.0.0-beta.35
[Appium] Non-default server args:
[Appium] {
[Appium]   relaxedSecurityEnabled: true
[Appium] }
[Appium] Attempting to load driver uiautomator2...
[debug] [Appium] Requiring driver at /Users/xx/.appium/node_modules/appium-uiautomator2-driver
[Appium] Attempting to load driver xcuitest...
[debug] [Appium] Requiring driver at /Users/xx/.appium/node_modules/appium-xcuitest-driver
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[Appium] Available drivers:
[Appium]   - [email protected] (automationName 'UiAutomator2')
[Appium]   - [email protected] (automationName 'XCUITest')
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.

Log move here https://gist.github.com/webinista/4d279268a09576ebca434f127feb8241

delete log here and put it in https://gist.github.com/ pls

no errors here

you still did not say what happen

also you may try yourself execute in terminal:

adb.exe -P 5037 -s emulator-5554 shell input text 234567

The OTP was not inputted into the android view. The script just ended

This works from terminal. How do l then use it in my code @Aleksei

Same as execute any terminal command for Java. Many ways.

Ps strange that does not work from Appium

new Actions(driver).sendKeys(otp).perform(); This worked for me.

1 Like

@Aleksei l have a new issue though. l am automating the screen below

when l use the below xpath to locate the first element
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]/android.widget.EditText[1][@index='1']")).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.view.View[2]/android.widget.EditText[1][@index='1']")).sendKeys("[email protected]");

it works well. but when l add the below xpath to my code, l get an error saying the first xpath is not located

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]/android.widget.EditText[2][@index='2']")).click();