无法将键发送到输入元素

时间:2019-06-05 08:04:51

标签: java mobile appium appium-android

我试图将登录凭据传递给输入字段,每次运行代码时,都会识别出输入字段,但是键没有在输入字段传递。请帮助...

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

1 个答案:

答案 0 :(得分:0)

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

因此,请先单击输入字段,然后使用以下代码段中提到的sendKeys输入值。

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

让我知道您是否仍然遇到任何问题。