Selecting all text in a region on a web page

Asked by gharabed

How would I select/copy all of the text in an img region I create? The text will vary in length from a few characters to the width of the web page I am copying it from. If I were to manually do it, I would just triple-click on the text and all of the text would be selected. Then I could copy and paste it. How would I triple click in Sikuli scripting or at least click and drag across the text I want?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

1. triple click not possible in current version
2. click(Match, modifier) (something like Shift-click) buggy right now ()

the strategie would be:
click in the upper left corner of the text region and then shift-click in the lower right corner.
Sorry, but not possible now because of a bug. just visit the bug and show you are affected, if you are.

Try something like that (uncomment the prints to get some tracking in the message area)

this script depends on the fact, that the region is fixed in pos and dim (e.g. app in fullscreen) and only the text varies.

s = <captured region> # the region of the screen, where the text is shown
(x, y, w, h) = (s.x, s.y, s.w, s.h) # get pos and dim of region
# print x, y, w, h
m1 = Match(x+60, y+100, 1, 1, 1) # absolute position of the first character
m2 = Match(x+w-5, y+h-5,1,1,1) # absolute position of a point in the lower right corner of the region
# print m
switchApp("Safari") # show browser window
sleep(1) # to avoid timing problems
doubleClick(m1) # select first word, doubleClick to get some visual feedback
click(m2, KEY_SHIFT) # may be it works with your system???

if the region varies, you have to evaluate the lower left corner by finding something near this corner and calculate your actual region:
s = <captured region> # the region of the screen, where the text is shown
(xTop, yTop, w, h) = (s.x, s.y, s.w, s.h) # get pos and dim of region
# this is still ok, but gives you only the upper left corner and the width (I guess, at least this can be fix)
f = find(<image>) # something down under ;-)
yOffset = 50 # you have to find out yourself
# so here is your actual region:
(x, y, w, h) = xTop, yTop, w, f.getY()-yOffset-yTop
# and here we go with the rest of the script

If you are affected by the bug, try with type(Key.DOWN, KEY_SHIFT), but this only works if you know or can calculate the number of lines your text has:
for i in range (number_of_lines):
    type(Key.DOWN, KEY_SHIFT)

Revision history for this message
RaiMan (raimund-hocke) said :
#2
Revision history for this message
Alberto Garcia (albegarca) said :
#3

Triple Click

This works for me:

click("SOME_IMAGE.png")
mouseDown(Button.LEFT)
mouseUp(Button.LEFT)
wait(0.01)
mouseDown(Button.LEFT)
mouseUp(Button.LEFT)

Can you help with this problem?

Provide an answer of your own, or ask gharabed for more information if necessary.

To post a message you must log in.