I'm trying to add some JS functions to a page but not sure how do it without assigning the function to the window object.
The following will work:
driver.execute_script("console.log('lalala');")
driver.execute_script("function momo(){console.log('lalala')};momo();")
But trying to do:
driver.execute_script("function momo(){console.log('lalala')};")
driver.execute_script("momo();")
will fail:
WebDriverException: Message: unknown error: momo is not defined
I know assigning the function to the window:
driver.execute_script("window.momo = function(){console.log('lalala')};")
will solve the issue, but maybe there is another way to do it?
Thanks.