2

As per project requirement i am working on Mobile App automation. Not problem arises when i executed same code which worked fine on emulator but when it comes to real device the same code were getting failed.the problem is UiAutomator is not able to locate element because of native keyboard come before an application during simulation. I executed this entire thing into Galaxy nexus which works on ANDROID API 18.hence no point to execute whole automation suites in Selendroid mode. in below code after filling value in first editbox,control should have reached to second editbox to fill value and so on. But it does not fill value there because native keyboard appear before 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 anyone who have idea to resolve this issue? Thanks in advance.

Priyank Shah

4

9 回答 9

2

首先,您应该了解软键盘是否处于活动状态 - 使用代码中的以下命令检查“mInputShown”参数 - 如果“真” - 活动软键盘。

 adb shell dumpsys input_method | grep mInputShown

使用此代码在运行旧版本 appium 的 Java-appium 中隐藏本机键盘。

driver.navigate().back()

PS - adb 命令对模拟器没有用,因为无论您的键盘是否处于活动状态,正在检查其值的标志始终设置为 true。

于 2014-06-23T06:36:54.117 回答
1

我认为你不能,而且这不是 appium 限制。根据我的观察,即使 UIAutomator 也找不到键盘隐藏的元素。

我知道2个解决方案:

  1. 关闭键盘。(我没有找到任何优雅的方法,所以我没有使用它。
  2. 在视图上滑动/滚动直到元素暴露,然后您可以对其进行操作。这对我来说很好。
于 2014-02-17T23:44:50.057 回答
0

您可以使用以下代码关闭键盘

driver.hideKeyboard();
于 2014-09-07T18:03:49.703 回答
0

如果您可以检测到键盘已打开,我建议您调用UiDevice.pressBack()来关闭键盘。

于 2014-07-24T20:48:45.000 回答
0

添加换行符也可以 editTextList.get(2).sendKeys("456\n");

于 2014-06-10T17:58:00.307 回答
0

您应该可以通过发送来关闭键盘

driver.findElement(By.name("Return")).click();
于 2014-02-28T17:50:37.130 回答
0

您可能需要启用 unicodeKeyboard: true您的 android 功能并使用键盘按钮 Return 隐藏键盘(如果显示)(这对我在 iOS 和 Android 上有效)

例如,我正在使用红宝石:

  element = $appium.find_element(id: field_id)
  element.clear
  element.send_keys(data)
  element.send_keys(:return) if driver.is_keyboard_shown
于 2020-01-26T11:00:27.930 回答
0

这是一个 uiautomator 就绪的全功能方法,如果键盘打开,则返回 true,如果关闭,则返回 false:

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);
    }

}
于 2016-04-29T05:09:44.997 回答
0

放入以下两行: driver.getKeyboard(); driver.hideKeyboard();

于 2016-01-22T12:17:08.327 回答