Sending Text using action class sends the text in the following format: "7
4"

I’m trying to insert the code sent to my email using automation.
the code will be added on android.view.view element and when I got the view and used sendKey function it doesn’t work.
I touched the screen then started writing the code using action class by the following piece of code:
tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), centerX, centerY));
tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(List.of(tap));
Actions action=new Actions(driver);
String code = custAPIs.getCode(apiUrl, userID);
action.sendKeys(code).perform();

I found the code added on the screen successfully but the code updated in the element content-desc by the following way:

Is there a way to send the keys without the special characters 7 4 6 0 2 6?

Hi,

How as user you type here numbers?
I guess you need first show keyboard with tap on first left square. After that keyboard will be shown and you type there your numbers. If it correct just do same. Tap on first square and send your six numbers to keyboard.

See example:

Hi,

This is what I actually did by the piece of code that touch the screen as it touches the first left square then the keyboard appears and I start writing the code using action class but I found that the value sent to the view content-desc attribute with the following representation “7 4 6 0 2 6”.

unfortunately, I don’t have text field for each square to send the code to it. the squares are just design of the view element which recieves the code.

that is why try just type text as user when keyboard open with

new Actions(driver).sendKeys("your text").perform();

I tried and here is the print of the page source:

this is arabic. and you tap on very RIGHT square that is first. correct?
can you share image after tap on it?


here is a screen after sending the code using the action class

so any issues here? you want to check entered text or ?

in your content-desc &#10 means New_Line symbol see https://www.freecodecamp.org/news/ascii-table-hex-to-ascii-value-character-code-chart-2/

just the way your app shows it. nothing more…

PS just for sure compare what it is after you manually do.

Here is the view when I send the code manually:


so how can I achieve this view using automation.

iiiiii

  1. try send NOT all text 123456 but one by one instead.
new Actions(driver).sendKeys("1").perform();
new Actions(driver).sendKeys("2").perform();
...

2. try with pressKey

((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.DIGIT_1));
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.DIGIT_2));


3. try with adb

adb shell input text ‘123455’

Hi,
I tried method #1 and #3 and still same issue.


I can’t use method #2 as I don’t know the keys I will press previously as I get them on runtime using a method.
so can you help me with any recommendation to solve this issue?

with method 2 you can use logic like:

    @Step("Press NumberKey Android")
    public boolean pressNumberKey_Android(String txt) {
        Logger.log();
        AndroidKey key = null;
        switch (txt) {
            case "0" -> key = AndroidKey.DIGIT_0;
            case "1" -> key = AndroidKey.DIGIT_1;
            case "2" -> key = AndroidKey.DIGIT_2;
            // ..
            default -> Assert.fail("Only numbers accepted");
        }
        try {
            ((AndroidDriver) driver).pressKey(new KeyEvent(key));
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

Unfortunately doesn’t work.

Lady, I am out of ideas. Next try ask app developers about such behavior.

Is it some problem for you? It does not accept code? Or you only have issue with compare what you entered?