appium: Sometimes 'An error occurred while executing user supplied JavaScript' error happens

Test case:

  1. Start app
  2. Type text to the UIATextField element
  3. Stop app
  4. Repeat 1-3 steps in cycle (100 iterations)
selenium.webdriver.remote.remote_connection: POST http://127.0.0.1:4723/wd/hub/session/aad3f7fb-fca5-493f-96b9-07b0525858e9/element/0/value {"sessionId": "aad3f7fb-fca5-493f-96b9-07b0525858e9", "id": "0", "value": ["t", "s", "o", "_", "u", "s", "e", "r", "_", "0", "0", "3", "0"]}
AppiumServer: debug: Appium request initiated at /wd/hub/session/aad3f7fb-fca5-493f-96b9-07b0525858e9/element/0/value
AppiumServer: debug: Request received with params: {"sessionId":"aad3f7fb-fca5-493f-96b9-07b0525858e9","id":"0","value":["t","s","o","_","u","s","e","r","_","0","0","3","0"]}
AppiumServer: info: Pushing command to appium work queue: "au.getElement('0').setValueByType('tso_user_0030')"
AppiumServer: debug: Sending command to instruments: au.getElement('0').setValueByType('tso_user_0030')
AppiumServer: info: [INSTSERVER] Sending command to instruments: au.getElement('0').setValueByType('tso_user_0030')
AppiumServer: info: [INST] 2013-12-03 12:20:04 +0000 Default: Got new command 7 from instruments: au.getElement('0').setValueByType('tso_user_0030')
AppiumServer: info: [INSTSERVER] Socket data received (153 bytes)
AppiumServer: info: [INSTSERVER] Socket data being routed for 'cmd' event
AppiumServer: info: [INSTSERVER] Got result from instruments: {"status":17,"value":"Cannot set value on invalid element: UIATextField from target.frontMostApp().elements()[0].elements()[4]"}
Message: u'An error occurred while executing user supplied JavaScript.' 
Traceback (most recent call last):
  ....
  File "/Library/Python/2.7/site-packages/selenium-2.35.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 165, in execute
    self.error_handler.check_response(response)
  File "/Library/Python/2.7/site-packages/selenium-2.35.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u'An error occurred while executing user supplied JavaScript.' 

Note: Xcode 5.0.2, iOS simulator 7.0.3, Appium 0.12.0 Appium in pre-lauched mode.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I just ran into this issue and the following debug logs from the appium server gave me a clue for a workaround:

info: [debug] [INST] 2015-10-05 17:13:41 +0000 Debug: No keyboard found. Tapping to make visible.


info: [debug] [INST] 2015-10-05 17:13:41 +0000 Debug: target.frontMostApp().elements()[0].elements()[1].elements()[0].elements()[2].tap()


info: [debug] [INST] 2015-10-05 17:13:41 +0000 Debug: Still no keyboard found. Tapping again to make visible.
info: [debug] [INST] 2015-10-05 17:13:41 +0000 Debug: target.frontMostApp().elements()[0].elements()[1].elements()[0].elements()[2].tap()
info: [debug] [INST] 2015-10-05 17:13:42 +0000 Debug: Error typing 'a': VerboseError: Could not locate keyboard.
info: [debug] [INST] 2015-10-05 17:13:42 +0000 Debug: Retrying...

This is happening in an embedded webview on iOS only.

I solved it by adding my own click actions using the same locator (xpath) that I gave to sendKeys. When I use my own click actions then the keyboard does appear and sendKeys is able to type the text.

It seems that there is a problem with Appium’s sendKeys method and clicking on the text field in embedded web views.

Tested using Appium version 1.4.13 and java-client 3.0.0

NB I was lucky I saw those server error logs. The ‘invalid javascript’ error message that the client receives is not very clear in this case.