import webdriver from 'selenium-webdriver';
const driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();
driver.get('https://www.google.com');
let foo = function(rules) {
rules.forEach(rule => {
rule();
});
}
let bar = function() { return 'bar' };
let baz = function() { return 'baz' };
driver.executeScript(foo, [bar, baz]).then(function(result) {
console.log(result);
});
driver.quit();
它出错了
WebDriverError: unknown error: rule is not a function
let foo = function(rules) {
return rules;
// rules.forEach(rule => {
// rule();
// });
}
let bar = function() { return 'bar' };
let baz = function() { return 'baz' };
driver.executeScript(foo, [bar, baz]).then(function(result) {
console.log(result); // refer the log pasted below
});
看起来函数正在被序列化string
[ 'function bar() {\n return \'bar\';\n}',
'function baz() {\n return \'baz\';\n}' ]
任何有关如何通过的指针array of functions as arguments
都会有所帮助。