execute_script a chunk of javascript?
Does it support a chunk of codes to be executed? In python i.e.
script = '''
var elements = $('CSS_SELECTOR').text().trim().split(' \n');
var length = elements.length;
var target = 'Stuff'
var exists = false;
for(var i = 0; i < length; ++i){
exists = elements[i].trim() === target? true : false;
if(exists){
break;
}
}
'''
browser.execute_script(script);
Then I received a lot of errors
WebDriverException: Message: u'{"errorMessage":"Parse error" ...)
Another example,
script = "var num = 2+2;"
context.browser.execute_script(script)
length = context.browser.evaluate_script('num')
length is appear to be None, and ErrorMSG is errorMessage":"Can\'t find variable: length"
After series of debugging. I figured out how it works.
It seems it failed on trim()
i.e.
var elements = $('CSS_SELECTOR').text().trim().split(' \n');
So what I figured out is, return the text of the DOM, then manipulate it in python using miniDOM and stuff like that.
However, I am looking for a more proper solution that can be used directly in JavaScript.
Closing this issue, since there's nothing we can fix here. Any issues with Webdriver parsing javascript should be raised with Selenium, not splinter.