sendKeys() failing

3,570 views
Skip to first unread message

Nilesh Kulkarni

unread,
Apr 21, 2013, 4:57:54 PM4/21/13
to appium-...@googlegroups.com
I started to play with Appium on wikipedia-iphone app. All I am trying to do is, type some text in the textField ''Search Wikipedia". Doing so I get an exception[1].

WebElement element = driver.findElement(By.tagName("textfield"));

element.sendKeys("Boston");

This is what I have tried so far. I tried to do element.clear(); it works but a keyboard appears after the textbox is cleared. I thought may be clearing that would help, but even hideKeyboard seems not working  js.executeScript("mobile: hideKeyboard");

I tried bunch of stuff in UIAutomation like setting the textField value, that didn't work either. I am kinda stuck right now and any help would be appreciated.

String script = "var textField = UIATarget.localTarget().frontMostApp().mainWindow().textFields();"

+ "textField[\"Search Wikipedia\"].setValue(\"Boston\");";

js.executeScript(script); //This throws exception too.


[1]org.openqa.selenium.WebDriverException: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().keyboard()

Command duration or timeout: 2.39 seconds

Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'

System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.2', java.version: '1.6.0_37'

Session ID: 1076b2e2-5661-47e6-8b1f-8285805467f8

Driver info: org.openqa.selenium.remote.RemoteWebDriver

Capabilities [{platform=MAC, databaseEnabled=false, javascriptEnabled=true, browserName=iOS, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, version=6.0}]

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)

at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)

at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)

at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)

at com.test.ios.HelloWorldApp.test(HelloWorldApp.java:65)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


Tomek

unread,
Apr 22, 2013, 2:18:50 AM4/22/13
to appium-...@googlegroups.com
Hello, 


what version of Appium do Yopu have? The newest one?

p.s. I check it on my local and cloud machine and for my app it works rpoperly, so, maybe it is some prblem with this Wikipedia elements, or exactly with not clearing the field?

TRY also WebElement element = driver.findElement(By.tagName("UIATextField")); instead of textfield, because it is mapped by appium, and now , if you tpye like in this, there is nomapping in path, maybe it will works



Tomek

Nilesh Kulkarni

unread,
Apr 22, 2013, 10:03:58 PM4/22/13
to Appium-discuss
This didn't work either, WebElement elems =
driver.findElement(By.tagName("UIATextField"));

My Appium version is 0.1.2

On Apr 22, 2:18 am, Tomek <two...@gmail.com> wrote:
> Hello,
>
> what version of Appium do Yopu have? The newest one?
>
> p.s. I check it on my local and cloud machine and for my app it works
> rpoperly, so, maybe it is some prblem with this Wikipedia elements, or
> exactly with not clearing the field?
>
> TRY also WebElement element = driver.findElement(By.tagName("*UIATextField*"));
> instead of textfield, because it is mapped by appium, and now , if you tpye
> like in this, there is nomapping in path, maybe it will works
>
> Tomek
>
> W dniu niedziela, 21 kwietnia 2013 22:57:54 UTC+2 użytkownik Nilesh
> Kulkarni napisał:
>
>
>
>
>
>
>
>
>
> > I started to play with Appium on wikipedia-iphone<https://github.com/wikimedia/wikipedia-iphone?source=cr>app. All I am trying to do is, type some text in the textField ''Search
> > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstru ctorAccessorImpl.java:27)
>
> > at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>
> > at
> > org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:1 87)
>
> > at
> > org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler. java:145)
>
> > at
> > org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554 )
>
> > at
> > org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:2 68)
>
> > at
> > org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java: 89)
>
> > at com.test.ios.HelloWorldApp.test(HelloWorldApp.java:65)
>
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3 9)
>
> > at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp l.java:25)
>
> > at java.lang.reflect.Method.invoke(Method.java:597)
>
> > at
> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod .java:47)
>
> > at
> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable. java:12)
>
> > at
> > org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.j ava:44)
>
> > at
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.ja va:17)
>
> > at
> > org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:2 6)
>
> > at
> > org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
>
> > at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
>
> > at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja va:70)
>
> > at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja va:50)
>
> > at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
>
> > at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
>
> > at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
>
> > at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
>
> > at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
>
> > at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
>
> > at
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestRe ference.java:50)

Jonathan Lipps

unread,
Apr 23, 2013, 12:12:33 AM4/23/13
to Nilesh Kulkarni, Appium-discuss
Sorry you're experiencing this, Nilesh. I can't remember any other app having trouble finding text field elements. Is your app a pure native app? Or is it hybrid? If it's hybrid, you'll have to enter a webview scope in order to find those elements.

Also, if you're looking for text elements, not textfield elements, the tag name is "text".
> --
> http://appium.io
> ---
> You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
> Visit this group at http://groups.google.com/group/appium-discuss?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

@jameseisenhauer

unread,
Apr 24, 2013, 4:06:03 PM4/24/13
to appium-...@googlegroups.com, Nilesh Kulkarni
I just upgraded to appium 0.3.0 and my scripts stopped working on the find text field.  It was previously on 0.0.12.

 I tried UIATextField to see if that changed things, before I was using textField.

The text field does not have a name so not sure if that is causing problems.

I am going to try and see if I can get older versions of appium and walk back version until I can find where it broke.

jim



#ruby 
puts "INFO: trying to find emailfield"
    emailfield = @driver.find_element(:tag_name, "UIATextField")
    puts 'INFO: Entering "' + email + '" into the first text field' 
    emailfield.send_keys(email) 


debug: Appium request initiated at /wd/hub/session/426173d5-1c64-44f3-947e-876b1033465f/element
debug: Request received with params: {"using":"tag name","value":"UIATextField"}
info: Pushing command to appium work queue: "au.getElementByType('UIATextField')"
debug: Sending command to instruments: au.getElementByType('UIATextField')
info: [INSTSERVER] Sending command to instruments: au.getElementByType('UIATextField')
info: [INST] 2013-04-24 19:16:58 +0000 Default: Got new command 4 from instruments: au.getElementByType('UIATextField')
info: [INSTSERVER] Socket data received (61 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":{"ELEMENT":"2"}}
info: Responding to client with success: {"status":0,"value":{"ELEMENT":"2"},"sessionId":"426173d5-1c64-44f3-947e-876b1033465f"}
POST /wd/hub/session/426173d5-1c64-44f3-947e-876b1033465f/element 200 1058ms - 109

@jameseisenhauer

unread,
Apr 25, 2013, 10:39:30 AM4/25/13
to appium-...@googlegroups.com, Nilesh Kulkarni
I got it working but not sure how.  I think a config issue of some sort, but will try to narrow down the issue on my main build laptop.

On my dev laptop, which is fairly new...I started going through the hack appium process http://appium.io/getting-started.html#hacking-with-appium
And somewhere in there it began to work.

So Nilesh I would suggest you at lest try those steps and run all the appium tests to see if they work.

jim

Pooja Shah

unread,
Mar 28, 2014, 4:53:24 AM3/28/14
to appium-...@googlegroups.com, Nilesh Kulkarni
hi Jonathan, I'm experiencing the same.
Using Appium 0.17.6 + webdriver  + IOS 7 + its not webview

Sendkeys doesn't work many times without any reason (not all the times)

with the similar structure "//window[1]/tableview[1]/cell[2]/textfield[1]")).sendKeys("aaaa");" works perfectly
but //window[1]/tableview[1]/cell[4]/textfield[1]")).sendKeys("aa");
doesnt work   (this page comes on click of more than 1 button , is Appium inspector getting wrong page source !!!!)

tried passing script like Nilesh and failed on that too



Attached UI hierarchy.

Please suggest....
Regards,
Pooja
Screen Shot 2014-03-28 at 2.14.23 pm.png

Wayne Ma

unread,
Mar 28, 2014, 7:04:51 PM3/28/14
to appium-...@googlegroups.com, Nilesh Kulkarni
I ams also seeing send_key and click error on the latest appium 0.17.6 build on my iPad test, especially when there are keyboard showing up at bottom, appium fails to find and click the button afterward.

Nilesh Kulkarni

unread,
Mar 30, 2014, 3:07:09 PM3/30/14
to Wayne Ma, appium-...@googlegroups.com
At that time, this is what I ended up doing at that time. I moved away to a different project and never tried sendKeys() in latest version of Appium. I used the apple automation instruments API and ran it is using JavascriptExecutor. This worked well for me. I know this is NOT ideal and appium should support this out of the box. But in case you are blocked, you can give this a shot until it is fixed in Appium.

JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;

public void setTextUsingAppleInstruments(String text) {

String script = "var vKeyboard = target.frontMostApp().keyboard();"

+ "vKeyboard.setInterKeyDelay(0.1);"

+ "vKeyboard.typeString(\"" + text + "\");";

jsExecutor.executeScript(script);

}

Pooja Shah

unread,
Mar 31, 2014, 5:30:25 AM3/31/14
to appium-...@googlegroups.com, Wayne Ma
Hi Nilesh,

thanks for replying, but how did it work for you? For me it throws exception:
WebDriverException: An error occurred while executing user supplied JavaScript.

Appium log :
info: [INSTSERVER] Sending command to instruments: var vKeyboard = target.frontMostApp().keyboard();vKeyboard.setInterKeyDelay(0.1);vKeyboard.typeString("Bangalore");

info: [INSTSERVER] Socket data received (138 bytes)


info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":17,"value":"'[object UIAElementNil]' is not a function (evaluating 'vKeyboard.setInterKeyDelay(0.1)')"}
info: Responding to client with error: {"status":17,"value":{"message":"An error occurred while executing user supplied JavaScript.","origValue":"'[object UIAElementNil]' is not a function (evaluating 'vKeyboard.setInterKeyDelay(0.1)')"},"sessionId":"9bf82019-4e97-4528-948e-dda5e419f683"}

POST /wd/hub/session/9bf82019-4e97-4528-948e-dda5e419f683/execute 500 1151ms - 278b

Please suggest...
Regards,
Pooja

Craig Schwarzwald

unread,
Aug 25, 2014, 5:43:02 PM8/25/14
to appium-...@googlegroups.com
This wasn't working for me either.  I found a work around that did work for me though.  Around selenium-java version 2.39 or so, they added a new interface to the WebDriver class "HasInputDevices".  As long as your using a selenium-java version of 2.39 or greater, you could try this solution that worked for me in Java:

((HasInputDevices) driver).getKeyboard().sendKeys("text you want to type");
For closing the standard keyboard after finished typing:
((HasInputDevices) driver).getKeyboard().pressKey(Keys.RETURN);

Jonah Stiennon

unread,
Aug 25, 2014, 7:46:56 PM8/25/14
to appium-...@googlegroups.com
You're saying sendKeys doesn't work with the java-client, but works with the selenium-java dirver?

Craig Schwarzwald

unread,
Aug 25, 2014, 9:12:54 PM8/25/14
to Jonah Stiennon, appium-...@googlegroups.com
I ran into an instance where:
webElement.sendKeys("text");
did not work for the iPad webElement I had in my Appium test code.

Since the keyboard on the iPad was already up, I had remembered some work I did in getting our WebDriver wrapper class up to spec when we moved to the 2.41 version of selenium-java, so I tried getting the keyboard object directly from the selenium-java WebDriver hard casting it to HasInputDevices, and doing sendKeys() off the keyboard object directly.  And that worked.  I'd have liked to have called sendKeys() off the webElement like I do in other places in my code, but this was I felt a reasonable solution since that didn't work for some reason.

Thanks.


--
http://appium.io
---
You received this message because you are subscribed to a topic in the Google Groups "Appium-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/appium-discuss/OPGf2VZFYc0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/d/optout.

Meenal Jain

unread,
Aug 26, 2014, 2:19:06 AM8/26/14
to appium-...@googlegroups.com, jon...@saucelabs.com
Hi All,

I'm facing the same issue. Is anybody able to find any solution to resolve this issue? Please suggest something to resolve the issue,I've tried finding elements by all means(tagname,classname,type,xpath,name) but nothing worked for me. If there is anything that worked for anyone please share.

Thanks,
Meenal
Reply all
Reply to author
Forward
0 new messages