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.


messageBubbleRegion = Region(1125,971,205,36).find("1487823213807.png")
while not exists("1487733279602.png"):
    click (messageBubbleRegion)
    print messageBubbleRegion.getScreen()
    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

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
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.

- 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)):
    for i in range (0,18):
       print message
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.

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.