Still Searching for imagelocation

[b]I have made this a bit more complicated and maybe confusing myself. Hoping you can clear my head.

The everyimagelocation function only works if the image you are looking for is on the screen. Problem I am having is you have to scroll down before the images appear. I have some code below:[/b]

repeat until imagefound("image_overall")
end repeat


// Find all occurances of image_overall on screen and right click to locate scheduling menu

put everyImageLocation("image_overall") into overallLocations

put the number of items in overallLocations into i

KeyDown ControlKey

Repeat while i > 0
	Click item i of overallLocations
	Subtract 1 from i
End Repeat
KeyUp ControlKey

TypeText "c"
wait 2.0

***** Problem I’m having is it stops after locating the first image so it never see’s the 2 or 10 images that are below. Can you please help me on this

This is tricky. I’ve reworked your code to do what I think you’re trying to do:

	repeat with each item of everyImageLocation("image_overall")
		RightClick it -- should do the same thing as controlkey + click
	end repeat
	-- capture an image that indicates you've reached the bottom of the page
	-- and use it in the following command
	if imageFound("ScrollBarAtBottom") then exit repeat
	TypeText pageDown
end repeat

-- I'm not clear on what the following code was meant to do, so I'm leaving it alone
TypeText "c"
wait 2.0

Some things to be aware of:

  • You need the repeat loop to process the images up until and including when you’ve scrolled all the way to the bottom of the page. This is accomplished with an infinite repeat loop that looks for the ending condition right before it tries to scroll down again; if it sees it’s at the bottom of the page, then it has already processed all the images and can exit the loop.

  • There’s always a chance that the thing that you’re looking for will be only partially displayed at the edge of the page, and the approach above (using pagedown) would probably miss this instance of that item. An approach that used the downarrow key would eventually catch all instances, but only by repeatedly finding the same image as it was scrolled up the screen. There’s also a strong possibility that using the approach above, images appearing near the bottom of the page will get clicked twice, as the last pagedown is likely to be only a partial page down.

  • The locations reported by everyImageLocation() are not locations on the page, but locations in the Remote Screen Window. So you can’t store locations as you scroll and have them have any meaning. If you do an everyImageLocation() and put it in a variable, then scroll, then click an item from the locations in the variable, you’re just clicking a point on the screen where something used to be. Or to put it another way, if your screen size is 800x600 and your page is 1800 pixels long, it will be displayed in 3 screenfulls, none of which will have a location coordinate bigger than (800, 600).

If the double processing of some items and the potential of missing some is not acceptable, then you’ll need to come up with a more elaborate script with more methodical scrolling. I’m not quite sure what the algorithm would look like for that.

I hope this helps.