如果本机键盘在您的应用程序之前出现,如何在 UIautomator 中定位元素? [英] How to locate element in UIautomator if native keyboard come before your application?

查看:16
本文介绍了如果本机键盘在您的应用程序之前出现,如何在 UIautomator 中定位元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据项目要求,我致力于移动应用自动化.当我执行在模拟器上运行良好的相同代码时不会出现问题,但是当涉及到真实设备时,相同的代码失败了.问题是 UiAutomator 无法定位元素,因为在模拟过程中本地键盘出现在应用程序之前.我在 Galaxy nexus 中执行了这整个事情,它适用于 ANDROID API 18.因此在 Selendroid 模式下执行整个自动化套件毫无意义.在下面的代码中,在第一个编辑框填充值后,控件应该已经到达第二个编辑框以填充值等等.但它并没有在那里填充值,因为原生键盘出现在应用程序之前.

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.

普里扬克·沙阿

推荐答案

首先你应该意识到软键盘是否处于活动状态 - 使用代码中的以下命令检查mInputShown"参数 - 如果true"- 主动软键盘.

First of all you should realize whether the soft keyboard is active or not - Use the following command from your code to check "mInputShown" parameter - If "true" - Active Soft Keyboard.

 adb shell dumpsys input_method | grep mInputShown

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

Use this code for hiding the native keyboard in Java-appium running older versions of appium.

driver.navigate().back()

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

P.S - The adb command is useless for emulators as the flag whose value is being checked is always set to true, whether your keyboard is active or not.

这篇关于如果本机键盘在您的应用程序之前出现,如何在 UIautomator 中定位元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆