I am inquiring about executing javascript in the browser with selenium. I've seen plenty of ways how to do this, however, saving the output to a variable seems to be something else.
r = driver.execute_script("`; ${document.cookie}`.split(`; bearer_token=`).pop().split(';').shift()")
This makes R = None, which is not the output of the code.
CodePudding user response:
execute_script() function in the selenium works for executing something particularly in the specific browser tab only, I am sure that the outputs won't be stored in a python variable. Instead I recommend to save the cookies in your local dir and later perform your tasks.
CodePudding user response:
You have to add the return statement:
r = driver.execute_script("return 2 2")
print(r)
will print 4.
And it will print None without return.
