I need to execute function written in JavaScript and also pass arguments.
value = driver.execute_script(open("path/file.js").read())
I can execute that file but I don't know how to pass arguments to that function. Any idea? Thanks!
I found out that I can pass arguments like that:
value = driver.execute_script(open("path/file.js").read(), "arg1", "arg2")
However, I had to change my JavaScript function. Now, it looks like that:
return (function click_on_element(path, method) {
...
})(arguments[0], arguments[1]);
I discovered that it is called a self-invoking function. Now, it is possible to pass arguments to JavaScript function and execute it using python and webdriver.