0 votes
1 view
in Devops and Agile by (25k points)

I'm using Selenium2 for some automated tests of my website, and I'd like to be able to get the return value of some JavaScript code. If I have a foobar() Javascript function in my webpage and I want to call that and get the return value into my Python code, what can I call to do that?

1 Answer

0 votes
by (63.3k points)

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 = []


[].forEach.call(cells, function (el) {

    if(el.text.indexOf("download") !== -1){



    //window.open(el.href, '_blank');




return URLs''')

 The result will contain the array that is URLs in this case. 

Hope this helps!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !