无法单击未使用 Appium Java 为 Android 应用程序启用的按钮
Not able to click a button which is not enabled using Appium Java for Android app
我必须创建一个传输。当我 运行 脚本时, 'Transfer' 按钮的 'enabled' 为假,因此脚本无法点击 'Transfer' 按钮并失败。我附上了 uiautomator 查看器转储的屏幕截图。
我找到的解决方法是手动单击金额编辑框,然后启用屏幕上的 android 键盘,然后为 'amount' 字段手动输入值,然后 'Transfer'按钮已启用并且可以单击。但我不确定如何从屏幕 android 键盘在编辑框中输入值,然后摆脱此键盘以输入日期并按 'Transfer' 按钮。
非常感谢您的帮助。谢谢
首先设置以下能力:
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方法会检查软键盘是否已经存在?如果它在那里,它只会隐藏软键盘。然后您将能够看到转账按钮。
希望这对你有用。谢谢!
我可以解决这个问题。我的做法是先点击'Amount'字段,然后sendkeys这个amount的值。有关详细信息,请参见以下代码:-
//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();
我必须创建一个传输。当我 运行 脚本时, 'Transfer' 按钮的 'enabled' 为假,因此脚本无法点击 'Transfer' 按钮并失败。我附上了 uiautomator 查看器转储的屏幕截图。
我找到的解决方法是手动单击金额编辑框,然后启用屏幕上的 android 键盘,然后为 'amount' 字段手动输入值,然后 'Transfer'按钮已启用并且可以单击。但我不确定如何从屏幕 android 键盘在编辑框中输入值,然后摆脱此键盘以输入日期并按 'Transfer' 按钮。
非常感谢您的帮助。谢谢
首先设置以下能力:
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方法会检查软键盘是否已经存在?如果它在那里,它只会隐藏软键盘。然后您将能够看到转账按钮。
希望这对你有用。谢谢!
我可以解决这个问题。我的做法是先点击'Amount'字段,然后sendkeys这个amount的值。有关详细信息,请参见以下代码:-
//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();