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

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

问题描述

根据项目要求,我正在从事移动应用自动化.当我执行在模拟器上可以正常工作的相同代码时,不会出现问题,但是当涉及到真实设备时,相同的代码却失败了.问题是UiAutomator无法定位元素,因为在仿真过程中,本机键盘先于应用程序出现.我将整个程序执行到可在ANDROID API 18上运行的Galaxy nexus中,因此没有必要在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.

Priyank Shah

Priyank Shah

推荐答案

首先,您应该意识到软键盘是否处于活动状态-使用代码中的以下命令检查"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天全站免登陆