How to wait and refresh untill a image is found ?

Asked by srijith

Im using Eclipse with Selinuim JAR file. I want to wait till a image is vanished, If a image is vanished, I want to proceed with my rest of the code, or else I want to do a sleep for 5 seconds and then refresh it and again check for image. Is there a way I can do it ? using some while loop or something ?

Also how to do the other way ? Instead waiting for a image to vanish, I want to wait for a image, If image is not there, then i want to sleep and refresh inside a while loop. Is it possible with Eclipse and Selinum JAR ?? thanks in advance.

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
Bunnings (sillybilly) said :
#1

For your first question, sikuli has

Region.waitVanish(Image path string OR Pattern, Timeout)

The other way to do it is by observing visual events in a region.

Region.OnAppear(Image, myeventhandler)

In the event handler you can say

def myeventhandler(self):
    Region.waitVanish(Image path string OR Pattern, Timeout)

Remember, if using events, you need to take care of start and start observing, define a timeout carefully.

Sample code from my project below

def CallThisMethodWhenYouNeedTo(self):
        self.screen.onAppear(self._ImgPostingTransactionMessage, self.WaitWhilePostingTransaction)
        self.screen.observe(Timeouts.Observe, background = False)

Event Handler
-----------------------
def WaitWhilePostingTransaction(self, event):
        self.screen.waitVanish(event.match, Timeouts.Wait)
        event.region.stopObserver()

Revision history for this message
Bunnings (sillybilly) said :
#2

The above answer will not cater for your refresh until image appears need. Try the following

def RefreshUntilImageAppears(self)

      img = region.exists(imagepath, 1)
      noofretry = 0

      while(img == None and noofretry < 5):
           RefreshPage();
           wait(1)
           img = region.exists(imagepath, 1)
           noofretry += 1

Obviously in the above logic(syntax may vary depending on your programming language) you can adjust the number of retries.
Also you can raise an error if the image is not found even after that.

Can you help with this problem?

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

To post a message you must log in.