How to find an item in UIautomator if the native keyboard goes in front of your application?

In accordance with the requirements of the project, I am working on the automation of mobile applications. Not a problem arises when I execute the same code that works fine on the emulator, but when it comes to the real device, the same code fails. The problem is that UiAutomator cannot find the item because the built-in keyboard comes in front of the application during the simulation. I did all this in Galaxy nexus, which is working on ANDROID API 18. You should not run whole automation kits in Selendroid mode. in the lower code, after filling in the value in the first edit field, the control should have reached the second editing field to fill in the value, etc. But it does not fill in the value there, because the built-in keyboard appears in front of the application.

SwipeableWebDriver driver = new SwipeableWebDriver( new URL("http://127.0.0.1:4723/wd/hub"), capabilities); List<WebElement> editTextList = driver.findElements(By .className("android.widget.EditText")); editTextList.get(0).sendKeys(c + "Bob"); editTextList.get(1).sendKeys("123"); editTextList.get(2).sendKeys("456"); el = driver.findElement(By.className("android.widget.Button")); el.click(); 

Please, who has an idea to solve this problem? Thanks in advance.

Priyank Shah

+2
source share
8 answers

First of all, you need to understand whether the soft keyboard is active or not. Use the following command from your code to check the "mInputShown" parameter. If true, the active soft keyboard.

  adb shell dumpsys input_method | grep mInputShown 

Use this code to hide your own keyboard in Java-appium, working with older versions of appium.

 driver.navigate().back() 

PS - The adb command is useless for emulators, since a flag whose value is checked is always true, regardless of whether your keyboard is active or not.

+2
source

I do not think you can do this, and this is not a limitation of the apium. From what I observed, even UIAutomator cannot find elements hidden by the keyboard.

I know 2 solutions for this:

  • Turn off the keyboard. (I have not found any elegant ways to do this, so I am not using it.
  • Scroll / scroll through the list until the item is open, and then you can execute it. This works great for me.
+1
source

you can remove the keyboard by sending

 driver.findElement(By.name("Return")).click(); 
0
source

adding a new line symbol is also editTextList.get (2) .sendKeys ("456 \ n");

0
source

If you find that the keyboard is open, I would suggest calling UiDevice.pressBack () to close the keyboard.

0
source

You can remove the keyboard using the following code

 driver.hideKeyboard(); 
0
source

Put the following two lines: driver.getKeyboard (); driver.hideKeyboard ();

0
source

Here is a ready-made fully functional uiautomator that will answer true if the keyboard is open and false if it is closed:

 public static boolean isKeyboardDisplayed() { String checkKeyboardCommand = "dumpsys input_method | grep mInputShown"; try { Process process = Runtime.getRuntime().exec(checkKeyboardCommand); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); int read; char[] buffer = new char[4096]; StringBuffer output = new StringBuffer(); while ((read = reader.read(buffer)) > 0) { output.append(buffer, 0, read); } reader.close(); process.waitFor(); if (output.toString().contains("mInputShown=true")) { return true; } else { return false; } } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } } 
0
source

All Articles