0

I am trying to inject some javascript code into my chrome selenium browser. The javascript contains a token that is only valid one time and therefore the javascript can only be executed once. To inject the javascript I have used:

driver.execute_script(toinject)

Where toinject contains this javascript:

javascript:(function(){ var f = document.createElement("form"); f.setAttribute("id","destroyer"); f.setAttribute("method","post"); f.setAttribute("action","http://www.adidas.ch/on/demandware.store/Sites-adidas-CH-Site/default/Cart-MiniAddProduct?clientId=c1f3632f-6d3a-43f4-9987-9de920731dcb"); var masterPid = document.createElement("input"); masterPid.setAttribute("type","hidden"); masterPid.setAttribute("name","masterPid"); masterPid.setAttribute("value","BY9913"); var pid = document.createElement("input"); pid.setAttribute("type","hidden"); pid.setAttribute("name","pid"); pid.setAttribute("value","BY9913_620"); var ajaxOption = document.createElement("input"); ajaxOption.setAttribute("type","hidden"); ajaxOption.setAttribute("name","ajax"); ajaxOption.setAttribute("value","true"); var responseOption = document.createElement("input"); responseOption.setAttribute("type","hidden"); responseOption.setAttribute("name","layer"); responseOption.setAttribute("value","Add To Bag overlay"); var quantity = document.createElement("input"); quantity.setAttribute("type","hidden"); quantity.setAttribute("name","Quantity"); quantity.setAttribute("value","1"); var sessionSelectedStoreID = document.createElement("input"); sessionSelectedStoreID.setAttribute("type","hidden"); sessionSelectedStoreID.setAttribute("name","sessionSelectedStoreID"); sessionSelectedStoreID.setAttribute("value","null"); var captchaToken = document.createElement("input"); captchaToken.setAttribute("type","hidden"); captchaToken.setAttribute("name","g-recaptcha-response"); captchaToken.setAttribute("value","03AMPJSYXHk0axYBy3sJEKk7pSbaubS9c0Du3y87zzid05zpMpMvyzWdqRQmbPqVM2cxd9j3RNjMyX7x3_NOmo7NhlJD0YjyZlwG13AIGwHZ9E0IYqX1YyxAO162pXPxZboq4M47CA9Sf2BDdwIPjHsPgOX3ELuFeWR38Su0jsrrJoQ1ti49wllmsM3EbfSM4PXoudbary0NmXrSC2qpkQ0H3SkIbW3cfiwnDPm6s5bWlznjFAwtuDBbWGm7FC2TizgPr_nVRW4hh7E9F_lEkTWS-BIQFsan2huh7z-eK1Q1WEYUC9ReDg87GoKPF0CAz3yfanh_hbfHr7yMVSxqkQznGXmNQ-tj8gfa9PVwKM5BUT_-ofQliUBgEWePQN31cStqRxDuUesGyB"); f.appendChild(captchaToken); var captchaDuplicate = document.createElement("input"); captchaDuplicate.setAttribute("type","hidden"); captchaDuplicate.setAttribute("name","x-PrdRt"); captchaDuplicate.setAttribute("value","03AMPJSYXHk0axYBy3sJEKk7pSbaubS9c0Du3y87zzid05zpMpMvyzWdqRQmbPqVM2cxd9j3RNjMyX7x3_NOmo7NhlJD0YjyZlwG13AIGwHZ9E0IYqX1YyxAO162pXPxZboq4M47CA9Sf2BDdwIPjHsPgOX3ELuFeWR38Su0jsrrJoQ1ti49wllmsM3EbfSM4PXoudbary0NmXrSC2qpkQ0H3SkIbW3cfiwnDPm6s5bWlznjFAwtuDBbWGm7FC2TizgPr_nVRW4hh7E9F_lEkTWS-BIQFsan2huh7z-eK1Q1WEYUC9ReDg87GoKPF0CAz3yfanh_hbfHr7yMVSxqkQznGXmNQ-tj8gfa9PVwKM5BUT_-ofQliUBgEWePQN31cStqRxDuUesGyB"); f.appendChild(captchaDuplicate); var s = document.createElement("input"); s.setAttribute("type","submit"); s.setAttribute("value","Submit"); f.appendChild(masterPid); f.appendChild(pid); f.appendChild(ajaxOption); f.appendChild(responseOption); f.appendChild(quantity); f.appendChild(sessionSelectedStoreID); f.appendChild(s); document.getElementsByTagName("body")[0].appendChild(f); })(); document.getElementById(document.querySelector("[id^='destroyer']").id).submit();

It is very long but im pretty certain it is correct because it works if I run it using a javascript tester. What happens after is, the javascript seems to be executed twice, making the token invalid. I get the following error:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "testin.py", line 74, in startbot
    openseission()
  File "testin.py", line 183, in openseission
    driver.execute_script(toinject)
  File "/Users/____/Desktop/going_headless/chaptcha/flask/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 546, in execute_script
    'args': converted_args})['value']
  File "/Users/____/Desktop/going_headless/chaptcha/flask/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
    self.error_handler.check_response(response)
  File "/Users/___/Desktop/going_headless/chaptcha/flask/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'
  (Session info: chrome=65.0.3305.0)
  (Driver info: chromedriver=2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3761eb3a03e),platform=Mac OS X 10.12.6 x86_64)

How can I avoid this? I have'nt found anyone with the same problem for the past 3 hours. I don't mind injecting the javascript another way but I don't know any. Thank you in advance

1
  • Seems the error is clear call function result missing 'value'. Can you check the JS if all the values are provided? Commented Dec 28, 2017 at 7:58

1 Answer 1

1

Your trace suggests you are using chrome 65 (are you on the beta channel?) w/chromedriver 2.34. I don't think chrome 65 can be driven with that version of chromedriver. You might want to downgrade chrome (e.g. to the stable version, currently 63, I believe).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.