Hi,
Sorry to bring this post back from retirement. I’ve tried to take the suggested solution above and extend it further, but I run into problems when I execute the script.
It runs fine up until the point that it tries to click relative to the image where it proceeds to bail out with the following.
Thanks in advance,
Deon.
Error -
SenseTalk Runtime Exception Invalid operands for addition: expected numbers, dates and/or lists; got ‘(0,35)’ and ‘’
It basically gets to this section and fails, any help figuring out what has gone wrong would be greatly appreciated.
if direction is "up" then
Click edge of bounds - (0,abs(distance))
else if direction is "left"
Click edge of bounds - (abs(distance),0)
else if direction is "down"
Click edge of bounds + (0,abs(distance))
else -- right
Click edge of bounds + (abs(distance),0)
end if
Called like -
Toolbox.clickRelativeTo “anImage”, down, 35
Full Script -
on clickRelativeTo anElement, direction, distance, optionalFrom
(*********************
Simple script which allows you to click a distance from the edge of a rectangle which bounds
an element, either image or text. The rectangle edge selected is based on the direction
specified. Up is Top, Left is Left, Down is Bottom and Right is Right.
By default the center of each edge is used as the start or From point. The From point can
optionally be specified, either left or right for Horizontal edges; top or bottom for vertical edges.
As we are specifying a direction, distance should always be a positive number so in all instances
the absolute value of distance will be used.
Will LogError when attempting to click on, or within, anElement's rectangle. Due to the absolute
value issue above this will only be possible if a distance of zero is used.
Parameters :
anElement : the Image, or Text, you want to click relative to
direction : "up", "down", "left", "right" (Not case sensitive)
distance : Number of pixels in "direction"
optionalFrom -
Optional field. If direction is "up" or "down" then only "left" or "right" can be used.
If direction is "left" or "right" then only "top" or "bottom" can be used.
If this field is left empty then "center" is used.
*********************)
if distance is 0 then
LogError("Distance must not be zero")
end if
try
if imageFound(anElement) then
put ImageRectangle(anElement) into bounds
else
put ImageRectangle(text:anElement) into bounds
end if
catch e
LogError("Error finding image or text["& anElement &"] : ", e)
end try
put ("up", "down") into validVerticalDirections
put ("left", "right") into validHorizontals -- Used for both direction and optionalFrom
put ("top", "bottom") into validVerticalFroms
if direction is "up" then
put "top" into edge
else if direction is "down" then
put "bottom" into edge
else if direction is in validHorizontals then
put direction into edge
else
LogError("Invalid direction [" & direction & "]")
end if
if optionalFrom is empty then
put edge & "Center" into edge
else
if ((optionalFrom is in validHorizontals and direction is in validVerticalDirections) or \
(optionalFrom is in validVerticalFroms and direction is in validHorizontals)) then
put edge & optionalFrom into edge
else
LogError("Invalid combination of direction and optionalFrom produces [" & edge & optionalFrom & "]")
end if
end if
Log("Direction is [" & direction & "]")
Log("Edge is [" & edge & "]")
Log("Distance is [" & distance & "]")
if direction is "up" then
Click edge of bounds - (0,abs(distance))
else if direction is "left"
Click edge of bounds - (abs(distance),0)
else if direction is "down"
Click edge of bounds + (0,abs(distance))
else -- right
Click edge of bounds + (abs(distance),0)
end if
end clickRelativeTo