2

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!

1 Answer 1

3

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.

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.