Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的Webdriver-执行JavaScript文件并向其函数传递参数_Javascript_Python_Selenium Webdriver - Fatal编程技术网

Python中的Webdriver-执行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

我需要执行用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(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执行它