How to restrict regions for the use of Region.text even with context menus of varying length

Asked by Nagarjun Jammalamadaka

I'm able to capture text from region using region.text() . Is it possible to capture a text from Screen-Shot(restricting inside region) in Web-Application.

One more thing I want to know is to reduce the size of region(photo-copy) inserted in script instead of entering co-ordinates.

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

The normal way, to be able to evaluate/calculate regions on the screen (not specifying its coordinates), is to start with a known region (e.g. app.window(), some match).
Knowing the geometry of the GUI/web-page, you can use the different region features (http://sikuli.org/docx/region.html)

example with this site:
m = find(<image-of-sikuli-logo.png>)
r = m.below(40).left(1).right(500)

would be the region containing the title of the question. This will be true, no matter, where on the screen the browser window is currently located.

Revision history for this message
Nagarjun Jammalamadaka (nagarjun-j) said :
#2

RaiMan,i went as per your suggestions.Now i'm able to capture text.Also one more point i wanted to know.

In some scenarios context menus are being displayed.Adding to that size of menu is not constant.What is the possible way to restrict region to size of context menus.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

What you can try, is to use the onChange() action of Sikuli's observe feature.

see docs: http://sikuli.org/docx/region.html#observing-visual-events-in-a-region

example:

def handler(event):
    print "In Change Handler"
    for m in event.changes:
        event.region.changes.append(Region(m))
    event.region.changes.append(None)
    event.region.stopObserver()

switchApp("Safari")
m = find("Newinversion.png") # to get a click point

r = m.left(1).right(500).above(1).below(500) # observed region
r.highlight(2) # within menu is expected

r.onChange(handler)
r.changes = []
r.observe(FOREVER, True) # background observation

rightClick(m) # main script continues

for i in range(20): # wait for the handler to terminate
    if len(r.changes) == 0: wait(1); continue
    if r.changes[-1]: wait(1); continue
if len(r.changes) < 2:
    print "Sthg. went wrong"
    exit(1)

for reg in r.changes[:-1]: # check the result
    reg.highlight(2)

the idea: you know the region where the menu should popup inside. This popping up menu changes the regions content. This is observed and as a result you get the part of the region, that has changed - which should be your popup menu.

It looks a bit complicated, but works. Since we want to know the changed region in our main script, we have to implement a storage to communicate this from the handler to the main script (r.changes as a list/array).
After the rightClick() we have to wait for the handler to terminate, which is done by checking the content of r.changes during max 20 seconds.

Can you help with this problem?

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

To post a message you must log in.