繁体   English   中英

无法单击使用Appium Java for Android应用未启用的按钮

[英]Not able to click a button which is not enabled using Appium Java for Android app

我必须创建一个转移。 当我运行脚本时,“已启用”的“转移”按钮为false,因此脚本无法点击“转移”按钮,并失败。 我已附上uiautomator浏览器转储的屏幕截图。 在此处输入图片说明

我发现的解决方法是手动单击金额编辑框,然后启用屏幕上的Android键盘,并通过为“金额”字段手动输入值,然后启用“转移”按钮并可以单击。 但是我不确定如何从屏幕上的android键盘在编辑框中输入值,然后摆脱此键盘以输入日期并按“转移”按钮。 在此处输入图片说明

非常感谢您的帮助。 谢谢。

首先设置以下功能:

capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);

第二种尝试通过以下方式隐藏键盘:

driver.hideKeyboard(); // doesn't work on newer versions of appium

或尝试以下方法:

driver.pressKeyCode(AndroidKeyCode.BACK);  //this also doesn't work on all devices but give it a try

对于日期控件,我不太确定您使用的是日期选择器还是某些自定义的日期控件,但是在每个操作上都尝试隐藏键盘。

嗨,您可以使用以下代码段隐藏软键盘。 这个对我有用。

public void someMethod(){
driver.getKeyboard();
        try {
            if (checkSoftKeyboard())
                driver.hideKeyboard();
        } catch (IOException e) {
            e.printStackTrace();
        }
}

public boolean checkSoftKeyboard() throws IOException {
        boolean isKeyboardPresent = false;
        Process p = Runtime.getRuntime().exec("adb shell dumpsys input_method | grep mInputShown");
        BufferedReader   in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String outputText = "";

        while ((outputText = in.readLine()) != null) {

            if(!outputText.trim().equals("")){
                String keyboardProperties[]=outputText.split(" ");
                String keyValue[]=keyboardProperties[keyboardProperties.length-1].split("=");

                String softkeyboardpresenseValue=keyValue[keyValue.length-1];
                if(softkeyboardpresenseValue.equalsIgnoreCase("false")){
                    isKeyboardPresent=false;
                }else{
                    isKeyboardPresent=true;
                }
            }
        }
        in.close();
        return isKeyboardPresent;
    }

checkSoftKeyboard方法将检查软键盘是否已经存在? 如果在那里,它将仅隐藏软键盘。 然后您将能够看到“ 转移”按钮。

希望这对您有用。 谢谢!

我能够解决这个问题。 我的方法是先单击“金额”字段,然后向sendkeys输入金额的值。 有关详细信息,请参见以下代码:-

    //locating the amount field using xpath
    MobileElement amount = driver.findElement(By.xpath("//android.widget.EditText[@resource-id='com.abc.rbanking:id/workflow_step_amount_value']"));

    amount.click();

    amount.sendKeys("1.25");
   //clicking and sendkeys would enable the disabled 'Transfer' button

   //locating the 'Date' field and click it. Clicking it would get rid of soft android keyboard
    driver.findElement(By.xpath("//*[@text = 'Date']")).click();

    Thread.sleep(3000);

    driver.findElement(By.id("com.abc.rbanking:id/back_button")).click();

    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    driver.findElement(By.xpath("//android.widget.Button[@resource-id='com.abc.rbanking:id/PrimaryButton' and @text='Transfer']")).click();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM