Sendkeys failing in iphone6

I am getting the following error with ios8 branch and trying to send a key.
client log

 Selenium::WebDriver::Error::JavascriptError:
   target.frontMostApp().keyboard() failed to tap 'k'

below is the appium log

info: [debug] Sending command to instruments: au.getElement(‘4’).setValueByType(‘kates Bakery\n’)
info: [debug] [INST] 2014-10-01 05:12:00 +0000 Debug: Got new command 16 from instruments: au.getElement(‘4’).setValueByType(‘kates Bakery\n’)
info: [debug] [INST] 2014-10-01 05:12:00 +0000 Debug: evaluating au.getElement(‘4’).setValueByType(‘kates Bakery\n’)
info: [debug] [INST] 2014-10-01 05:12:00 +0000 Debug: target.frontMostApp().keyboard().typeString(“k”)
info: [debug] [INST] 2014-10-01 05:12:00 +0000 Debug: target.frontMostApp().keyboard() failed to tap ‘k’
info: [debug] [INST] 2014-10-01 05:12:00 +0000 Debug: Error typing ‘k’: VerboseError: target.frontMostApp().keyboard() failed to tap ‘k’
info: [debug] [INST] 2014-10-01 05:12:00 +0000 Debug: Retrying…
info: [debug] [INST] 2014-10-01 05:12:00 +0000 Debug: target.frontMostApp().keyboard().typeString(“k”)
info: [debug] [INST] 2014-10-01 05:12:01 +0000 Debug: target.frontMostApp().keyboard() failed to tap ‘k’

I’m getting this as well.

info: [debug] Pushing command to appium work queue: "au.getElement('7').setValueByType('[email protected]')"
info: [debug] Sending command to instruments: au.getElement('7').setValueByType('[email protected]')
info: [debug] [INST] 2014-10-01 01:53:29 +0000 Debug: Got new command 13 from instruments: au.getElement('7').
setValueByType('[email protected]')
info: [debug] [INST] 2014-10-01 01:53:29 +0000 Debug: evaluating au.getElement('7').setValueByType(
'[email protected]')
info: [debug] [INST] 2014-10-01 01:53:29 +0000 Debug: target.frontMostApp().keyboard().typeString("a")
info: [debug] [INST] 2014-10-01 01:53:29 +0000 Debug: target.frontMostApp().keyboard() failed to tap 'a'
info: [debug] [INST] 2014-10-01 01:53:29 +0000 Debug: Error typing 'a': VerboseError: target.frontMostApp().keyboard
() failed to tap 'a'
info: [debug] [INST] 2014-10-01 01:53:29 +0000 Debug: Retrying...
info: [debug] [INST] 2014-10-01 01:53:29 +0000 Debug: target.frontMostApp().keyboard().typeString("a")
info: [debug] [INST] 2014-10-01 01:53:29 +0000 Debug: target.frontMostApp().keyboard() failed to tap 'a'

I’m using Java, calling driver.findElement(MobileBy.className("UIATextField")).sendKeys("[email protected]"). Is there a way to enter the entire string into the text field at once? Or does iOS have to enter one character at a time?

Hi,

A much faster way to get around this is to use the .setValue() method.

E.g. using By.xpath in Java

((MobileElement) driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]"))).setValue("somethingrandom");

Hope this helped.

Andrew

2 Likes

Thanks! That fixed it for me. I had to upgrade to Java 7 and upgrade the java-client to v2.0.0.

Can we do the same with ruby_lib

Hi,

@Satyajit I found the following thread that might be of some use to you:

Hope this helps.

Andrew

Thanks @AndyDee that pointed me right direction. But can anyone tell me how to send ENTER to the text field? send_keys would take ‘\n’ but not setValue

Hi,

@Satyajit, what do you need the ‘enter’ for?

Enter is:
driver.findElement(By.xpath("/someXpath")).sendKeys("\n");

The purpose of .setValue() is to completely skip any keyboard interraction and override the object field’s value with whatever you give the arguments of the method.
Using both together on the other hand would look like:

((MobileElement) driver.findElement(By.xpath("/someXpath"))).setValue("somethingrandom");
driver.findElement(By.xpath("/someXpath")).sendKeys("\n");

Andrew

1 Like

I get the following error with \n

ruby_lib log

post /element/6/value
{
:value => [
[0] “\n”
]
}
Selenium::WebDriver::Error::JavascriptError: target.frontMostApp().keyboard() failed to tap ’

from /Library/Ruby/Gems/2.0.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok’

appium log ( I am on ios8 branch Appium v1.3.0-beta1 (REV 314bb546d290beb264656d4c86f6dc8c646ed9bd))

info: ← POST /wd/hub/session/1ab2f220-939f-4cb6-a413-1b924359b6f6/element/6/value 500 1779.665 ms - 212
info: [debug] [INST] 2014-10-09 17:48:10 +0000 Error: VerboseError: target.frontMostApp().keyboard() failed to tap ’

info: [debug] [INST] 2014-10-09 17:48:10 +0000 Error: Error during eval: typeString@[native code]
sendKeysToActiveElement@file:///Users/smalugu/code/appium_ios8/0B7D5302-886E-4FE6-A352-A31F77FD1BAB/bootstrap-2c0b02acfaf99c28.js:1265:32
setValueByType@file:///Users/smalugu/code/appium_ios8/0B7D5302-886E-4FE6-A352-A31F77FD1BAB/bootstrap-2c0b02acfaf99c28.js:1955:38
eval code
eval@[native code]
startProcessing@file:///Users/smalugu/code/appium_ios8/0B7D5302-886E-4FE6-A352-A31F77FD1BAB/bootstrap-2c0b02acfaf99c28.js:2646:30
bootstrap@file:///Users/smalugu/code/appium_ios8/0B7D5302-886E-4FE6-A352-A31F77FD1BAB/bootstrap-2c0b02acfaf99c28.js:2712:31
global code@file:///Users/smalugu/code/appium_ios8/0B7D5302-886E-4FE6-A352-A31F77FD1BAB/bootstrap-2c0b02acfaf99c28.js:2721:10
info: [debug] [INST] 2014-10-09 17:48:10 +0000 Debug: responding with:
info: [debug] [INST] 2014-10-09 17:48:10 +0000 Debug: Running system command #18: /usr/local/Cellar/node/0.10.28/bin/node /Users/smalugu/code/appium_ios8/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:17,“value”:“target.frontMostApp().keyboard() failed to tap ‘\n’”}…

Oh making the soft keyboard show up solved all my problems. RFTM - https://github.com/appium/appium/blob/ios8/docs/en/appium-setup/running-on-osx.md#system-setup-ios

1 Like

Have you tried on a simulator? Were you able to make the send keys work when connected to a device too? Please share the exact steps.

This worked on a simulator, i just pressed cmd+k the first time a text box showed up and it worked. I haven’t tried it on a device yet (but devices already popup a keyboard), so send_keys should work directly

Hi @AndyDee : i’m facing casting exception while using MobileElement
org.openqa.selenium.remote.RemoteWebElement cannot be cast to io.appium.java_client.MobileElement
Details on- MobileElement Class cast exception

which OS and xcode you are using

use

type

instead of

send_keys

Was this issue fixed? I do not have type or setValue property just sendKeys. But it doesn’t work. I get the same error as above.