java - 无法将按键发送到输入元素

标签 java mobile appium appium-android

我试图将登录凭据传递到输入字段,每次运行代码时,输​​入字段都会被识别,但 key 不会在输入字段传递。请帮忙...

Code:
WebElement image=driver.findElement(By.xpath("//android.widget.Image[@content-desc='LandingPAge']"));
System.out.println("Landed Login page");
driver.findElementByXPath("//android.view.View[@content-desc='Username']").sendKeys("u3@gmail.com");
driver.findElementById("password").sendKeys("1231212");
driver.findElementByXPath("//android.widget.Button[@content-desc='Login']").click();

Appium Log Details: 
[debug] [W3C (235592b3)] Calling AppiumDriver.setValue() with args: [["u","3","@","g","m","a","i","l",".","c","o","m"],"2","235592b3-a8eb-4ccb-8d22-fef43fa92679"]
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:setText","params":{"elementId":"2","text":"u3@gmail.com","replace":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"2","text":"u3@gmail.com","replace":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: setText
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using element passed in: 2
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Attempting to clear using UiObject.clearText().
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"UiSelector[CLASS=android.view.View, INSTANCE=5]"}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
[debug] [W3C (235592b3)] Encountered internal error running command: NoSuchElementError: UiSelector[CLASS=android.view.View, INSTANCE=5]

Ecllipse Console Error:
[RemoteTestNG] detected TestNG version 6.14.2
Jun 05, 2019 1:03:25 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Landed Login page
FAILED CONFIGURATION: @BeforeClass setUp
org.openqa.selenium.NoSuchElementException:
UiSelector[CLASS=android.view.View, INSTANCE=5]
For documentation on this error, please visit:
http://seleniumhq.org/exceptions/no_such_element.html

最佳答案

尽管您像 selenium sendKeys 一样在输入字段中输入文本,但有时 appium 无法正常工作。

因此,首先单击输入字段,然后使用 sendKeys 输入值,如下面的代码片段所述。

driver.findElement(By.id("#loc")).click();
driver.findElement(By.id("#loc")).sendKeys("text);

如果您仍然遇到任何问题,请告诉我。

关于java - 无法将按键发送到输入元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56456429/

相关文章:

android - html5 和 xamarin 有什么区别?

java - android Appium WebDriver 中向下滚动的问题

java - 如何将用户重定向到 Cloud Firestore 中的特定 Activity ?

java - 使用 google-guice 注入(inject)列表的最佳方法是什么?

android - 图片前面的 Nativescript CSS 文本

javascript - 为移动应用柏树或鸦片测试自动化工具之间有何更好的选择?

ios - 启动 appium 时仪器崩溃

java - 如何获取数字小数部分的长度?

java - java中的嵌套类

android - Flex 移动项目 : Numeric Keyboard