var = driver.execute_script("setTimeout(function(){ return [1,2,3]; }, 1000);")
Using Selenium's function execute_script, I'm trying to get data out of a website using javascript and pass it to a python variable var, the problem is that the javascript code that collects the data takes around 1 second to complete collecting the data (because of some animations), so when the line of code above is executed, the right value at that time is None (because the javascript code didn't return anything), but, 1 second later the right value will be changed to the data needed, still var will be None because that's the value assigned to it.
Note that this line of code works well, but that's not exactly what needed.
var = driver.execute_script("return [1,2,3];")
I have solutions to the problem but I'm looking for better ones:
- let the javascript code download the data to a file, and after
time.sleepfor the python code, let var get the data from that file - similar to 1, let the javascript code push the data to somewhere in the website, and after
time.sleepfor the python code, let var get the data from the website. - just use raw
Seleniumcode, which I don't prefer because I don't know other than the basics ofSelenium