Python中的Webdriver-执行JavaScript文件并向其函数传递参数
我需要执行用JavaScript编写的函数并传递参数Python中的Webdriver-执行JavaScript文件并向其函数传递参数,javascript,python,selenium-webdriver,Javascript,Python,Selenium Webdriver,我需要执行用JavaScript编写的函数并传递参数 value = driver.execute_script(open("path/file.js").read()) 我可以执行该文件,但我不知道如何将参数传递给该函数。 有什么想法吗?谢谢 我发现我可以像这样传递参数: value = driver.execute_script(open("path/file.js").read(), "arg1", "arg2") return (function click_on_element(p
value = driver.execute_script(open("path/file.js").read())
我可以执行该文件,但我不知道如何将参数传递给该函数。
有什么想法吗?谢谢 我发现我可以像这样传递参数:
value = driver.execute_script(open("path/file.js").read(), "arg1", "arg2")
return (function click_on_element(path, method) {
...
})(arguments[0], arguments[1]);
然而,我不得不改变我的JavaScript函数。
现在看起来是这样的:
value = driver.execute_script(open("path/file.js").read(), "arg1", "arg2")
return (function click_on_element(path, method) {
...
})(arguments[0], arguments[1]);
我发现它被称为自调用函数。现在,可以将参数传递给JavaScript函数,并使用python和webdriver执行它