I'm trying to return multiple PNG images for each mouse_click. I've set it up so that I can get multiple coordinates of a click, and then store those coordinates in a table. Then, loop the keys/values of the table to get each click. However, when I run the entire function it only produces the first page produced by splash.args.url, and does not include the clicks inside the loop. How can I integrate the clicks inside the loop effectively to produce multiple images?
treat = require("treat")
function page_info(splash, url)
local ok, msg = splash:go(url)
if not ok then
return {ok=false, reason=msg}
end
local res = {
html=splash:html(),
title=splash:evaljs('document.title'),
image=splash:png(),
ok=true,
}
return res
end
function main(splash)
assert(splash:go(splash.args.url))
local get_dimensions = splash:jsfunc([[
function () {
var rect = document.querySelector('checkbox[number="1"]').getClientRects()[0];
var rect2 = document.querySelector('checkbox[number="2"]').getClientRects()[0];
return {"x": rect.left, "y": rect.top,
"x2": rect2.left, "y2": rect2.top}
}
]])
splash:set_viewport_full()
splash:wait(0.1)
local dimensions = get_dimensions()
-- FIXME: button must be inside a viewport
local stuff = {[dimensions.x]=dimensions.y,
[dimensions.x2]=dimensions.y2}
local result = treat.as_array({})
local a = 1
for keys, values in ipairs(stuff) do
while a < 3 do
splash:mouse_click(keys, values)
a = a+1
result[a] = page_info(splash, url)
end
end
-- Wait split second to allow event to propagate.
splash:wait(0.1)
return result
end
I can run each click successively, however how can I store the results of each click and return it?
As I get an empty array:
Splash Response: Array[0]