question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
nicolasavenzacommented, Oct 5, 2015

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.

0reactions
lock[bot]commented, Apr 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

An error occurred while executing user supplied JavaScript
Exception in thread "main" org.openqa.selenium.WebDriverException: An > error occurred while executing user supplied JavaScript.
Read more >
JavaScript error - WebDriver - MDN Web Docs
The JavaScript error is a WebDriver error that occurs when a script the supplied by the user fails to execute.
Read more >
5 Common Causes of JavaScript Errors (and How to Avoid ...
The error is thrown because JavaScript code is usually executed according to the order it appears on a document. As such, the browser...
Read more >
JavaScript errors in Dreamweaver - Adobe Support
Common causes of JavaScript errors in Dreamweaver include a conflicting Dreamweaver extension, a conflict with code on a page, or a bad ...
Read more >
Introducing: Click Errors and JavaScript Error Details
Not all JavaScript errors are the same—they can vary greatly based on user details (like browser, OS, country), different parts of your script, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found