You can return values even if you don't have your snippet code written as a function like in the below example code, by just adding return var; at the end will work, where var is the variable you want to return.
result = driver.execute_script('''cells = document.querySelectorAll('a');
URLs = []
console.log(cells);
[].forEach.call(cells, function (el) {
if(el.text.indexOf("download") !== -1){
//el.click();
console.log(el.href)
//window.open(el.href, '_blank');
URLs.push(el.href)
}
});
return URLs''')
The result will contain the array that is URLs in this case.
Hope this helps!
If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training course!