How to deal with getting text from dynamic bubble region

Asked by Anupam on 2017-02-23

Hi, I am trying to automate a chat application. For capturing text from the message bubble i am using below mentioned code.

count=0

messageBubbleRegion = Region(1125,971,205,36).find("1487823213807.png")
while not exists("1487733279602.png"):
    messageBubbleRegion.above(count)
    click (messageBubbleRegion)
    print messageBubbleRegion.getScreen()
    count=count+46
    wheel(WHEEL_UP,1)
    print messageBubbleRegion.text().strip()

from the above code i am trying to move region upwards and capture the text in the new region.

But i am always getting same text in the ide console until the screen starts scrolling upwards that too some times text is not copied correctly.

Kindly help me out in this. Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2017-02-24
Last query:
2017-02-24
Last reply:
2017-02-23
Best RaiMan (raimund-hocke) said : #1

already tried to use copy to clipboard (click and select all) and then get the text from the clipboard.

The Region.text() feature is not very reliable yet.

BTW:
- you do not change the messageBubbleRegion: above() returns a new region object.
- you should add a suitable wait(x) after the wheel() e.g. wait(1)
- while not exists("1487733279602.png", 0): is faster (searches only once) and should be restricted to a region calculated from messageBubbleRegion

Anupam (anupamt) said : #2

Hi, Sorry for delayed response

I tried the clipboard solution along with doubleClick() function and it work well now. This is what i implemented

while not exists(Pattern("1487911529987.png").targetOffset(80,-4)):
    x,y=(1196,992)
    for i in range (0,18):
       wait(2)
       type("c",KEY_CTRL)
       wait(2)
       message=Env.getClipboard()
       print message
       wait(2)
       y=y-45
       mouseMove(Location(x,y))
       wait(2)
       doubleClick(Location(x,y))
    wheel(WHEEL_UP,11)
    wait(2)
This seems working more accurate then region.text() so i left that approach.

Thanks for your prompt help!

Anupam (anupamt) said : #3

Thanks RaiMan, that solved my question.

Anupam (anupamt) said : #4

Let me know if i can optimize it a bit more to be more flexible.
Thanks

RaiMan (raimund-hocke) said : #5

while not exists(Pattern("1487911529987.png").targetOffset(80,-4)):

the only thing to optimise:
while not expectedRegion.exists(Pattern("1487911529987.png").targetOffset(80,-4), 0):
- expectedRegion: if you somehow define the region, where you expect your pattern to appear, it would be faster
- exists( ... , 0): only one search (otherwise it would wait 3 seconds if not there)

the other things to get more flexible would only be to put it in a def(), if you need this feature more often with different setups, and define the now fixed values as variables/parameters.