weixin_39572409
weixin_39572409
2021-01-07 20:54

Selenium Webdriver using SlimerJS fails to return JavaScript value from "execute_script"

versions

  • SlimerJS: 0.10.3
  • Firefox: 52.0.2 32bit
  • Operating system: Win10 64bit
  • IPython 5.1.0 (Python 2.7.11 |Anaconda 2.4.1 (64-bit))
  • selenium-3.3.3

Steps to reproduce the issue

IPython session * after patched services.py to use -w instead of --webdriver parameter, see issue #608 * could be related to #389


In [1]: from selenium import webdriver

In [2]: driver = webdriver.PhantomJS(executable_path=r"C:/dev/slimerjs-0.10.3/slimerjs.bat")

In [3]: driver.execute_script('var a =5; return a;')
---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-3-184ec43ea4af> in <module>()
----> 1 driver.execute_script('var a =5; return a;')

C:\Python27-64bit\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in execute_script(self, script, *args)
    482         return self.execute(command, {
    483             'script': script,
--> 484             'args': converted_args})['value']
    485
    486     def execute_async_script(self, script, *args):

C:\Python27-64bit\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in execute(self, driver_command, params)
    247         response = self.command_executor.execute(driver_command, params)
    248         if response:
--> 249             self.error_handler.check_response(response)
    250             response['value'] = self._unwrap_value(
    251                 response.get('value', None))

C:\Python27-64bit\lib\site-packages\selenium\webdriver\remote\errorhandler.pyc in check_response(self, response)
    162             if exception_class == ErrorInResponseException:
    163                 raise exception_class(response, value)
--> 164             raise exception_class(value)
    165         if message == "" and 'message' in value:
    166             message = value['message']

WebDriverException: Message: Error - Unable to load Atom 'execute_script' from file 'undefined/third_party/webdriver-atoms/execute_script.js'
</module></ipython-input-3-184ec43ea4af>

Starting debug session to inspect the caller stack:


%debug
ipdb> u
ipdb> u
ipdb> u
> C:\Python27-64bit\lib\site-packages\selenium\webdriver\remote\webdriver.py(249)execute()
    247         response = self.command_executor.execute(driver_command, params)
    248         if response:
--> 249             self.error_handler.check_response(response)
    250             response['value'] = self._unwrap_value(
    251                 response.get('value', None))

ipdb> driver_command
'executeScript'

ipdb> params
{'sessionId': u'19ed0b10-202a-11e7-9263-83a46c5c4f64', 'args': [], 'script': 'var a =5; return a;'}

ipdb> self.command_executor
<selenium.webdriver.remote.remote_connection.remoteconnection object at>

ipdb> self
<selenium.webdriver.phantomjs.webdriver.webdriver>
ipdb> response
{'status': 404, 'value': u"Error - Unable to load Atom 'execute_script' from file 'undefined/third_party/webdriver-atoms/execute_script.js'"}
</selenium.webdriver.phantomjs.webdriver.webdriver></selenium.webdriver.remote.remote_connection.remoteconnection>

Why is there a 'undefined/...? Is this correct or part of the problem?

Actual results:

WebDriverException: Message: Error - Unable to load Atom 'execute_script' from file 'undefined/third_party/webdriver-atoms/execute_script.js'

Expected results:

Return value to Python is expected to be 5

该提问来源于开源项目:laurentj/slimerjs

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐