10

I am having issues on performing send keys in a particular EditText field. I tried a dirty xpath and id but still it does not enter into the text field. However I feel like it is having no issue finding the element. It doesn't click into the element however.

So what happens in the app is that when the user selects the page, it opens up a web view and the EditText field is in that WebView.

Here is the dirty xpath I got from the appium inspector:

/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup/android.support.v4.view.ViewPager/android.view.ViewGroup/android.widget.EditText[1]

Here is the nice id:

@FindBy(id = "test_number")
public WebElement testNumberTextField;

I tried using find by xpath using the dirty xpath as well.

Here is my method where I try to enter the text. You can see by the commented code that I tried other things as well to get it working but still no success:

    public void enterTestNumber(){
    //List<WebElement> menu22 =drive.getDriver().findElements(By.className("android.widget.EditText"));
   // menu22.get(1).sendKeys(randomStringGeneratorMethods.randomAlphaNumericString(7));
    testPage.testNumberTextField.sendKeys(randomStringGeneratorMethods.randomAlphaNumericString(7));
    //js.executeScript("document.getElementById('"+testPage.testNumberTextField+").value='"+randomStringGeneratorMethods.randomAlphaNumericString(7)+"';");
    }

The random generator is just a random string generator which is this:

public String randomAlphaNumericString(int characterLength) {
    return RandomStringUtils.randomAlphanumeric(characterLength);
}

Does anyone know how to get this working so that it can type text into this EditText field?

aminography
  • 21,986
  • 13
  • 70
  • 74
BruceyBandit
  • 3,978
  • 19
  • 72
  • 144
  • what was your menu22 size? Do you get any error message with `testNumberTextField`? – supputuri May 10 '19 at 18:20
  • It didn't output a size nor did it give me an error. I tried a system.out.println but got no output. I could try and add the size and run it but the servers are down now till Monday – BruceyBandit May 10 '19 at 18:53
  • 1
    If an element is an "editText" then it would NOT be in a web view. Please add a screenshot of your UIAutomator screen if this is a native or hybrid app, or the appropriate HTML code through a chrome browser that points to the exact element if this is a web app. – Bill Hileman May 15 '19 at 14:44
  • @Brucey you are sastisfied with the answers or you need more help or suggestions – akshay patil May 18 '19 at 05:10
  • I realised there was no issue, the reason it wasn't working was because I had to do a mvn clean test before running it. It didn't update my code of my sendKeys code so that's why it did not enter. I didn't have to do a mvn clean text before but now it seems like I have to before running tests – BruceyBandit May 19 '19 at 10:12

5 Answers5

4

As the element is in the webview, you need to find the element html using chrome/firefox as the android ui automator would not be able to detect that element.

To get the html of the element, you need to connect your device with chrome and go to chrome://inspect, now operate in your app and open the webview, you would find your device in the chrome://inspect link as soon as the webview gets opened, you need to select your device from there and you would see the replica of the webview, from there you can inspect the element and find the html of the element and using that html you can get the xpath.

Now you have got the xpath, you just need to switch the driver to the webview from your code now and then you can enter the value in the field using sendKeys() method.

Sameer Arora
  • 4,439
  • 3
  • 10
  • 20
3

I haven't tried this, but you could send adb shell command input text. after clicking the element.

with the Appium mobile command feature.

https://appium.io/docs/en/commands/mobile-command/

wpj
  • 206
  • 2
  • 14
0

If focus is not in the textfiled after page is loaded, you need:

element.click();

before

element.sendKeys();
pburgr
  • 1,722
  • 1
  • 11
  • 26
0

Since you are able to find the element, but don't seem to be able to interact with it, a workaround could be to work with its coordinates instead.

  1. Click the coordinates to set the focus on the element.
  2. Input the keys without specifying a element.

I'm not experienced in java, so here is some pseudo code to give you a general idea:

item = driver.findElementByAccessibilityId("test_number");
driver.Mouse.Click(item.coordinates);
driver.pressKey(new KeyEvent(AndroidKey.ENTER));

You will probably need to iterate your random string and put the pressKey function in that loop to press every key.

PixelPlex
  • 749
  • 5
  • 21
0

I had problems once with a textfield input and this helped.

driver.update_settings({"ignoreUnimportantViews":True})
wpj
  • 206
  • 2
  • 14