python - creating and executing a Javascript function with Selenium -
i trying create , execute javascript function selenium. doing this:
js_func = """ function blah(a, b, c) { . . . }; """ self.selenium.execute_script(js_script) self.selenium.execute_script("blah", 1,2,3)
i don't errors first 1 (creating function), second 1 gives me:
webdriverexception: message: u'blah not defined'
is i'm doing valid? how can tell if function created? how can see errors (assuming there errors)?
it's how selenium executes javascript:
the script fragment provided executed body of anonymous function.
in effect, code is:
(function() { function blah(a, b, c) { ... } })(); (function() { blah(1, 2, 3); });
and due javascript's scoping rules, blah
doesn't exist outside of anonymous function. you'll have make global function:
window.blah = function(a, b, c) { ... }
or execute both scripts in same function call.
Comments
Post a Comment