how to tell when vertical scroll bar is no longer present

Asked by eve flowers

When the window is first displayed, the vertical scroll bar is present. I increase the height of the window until the vertical scroll bar is no longer present. I am using an image of the up arrow on the vertical scroll bar so that I can break out of the loop when the vertical scrollbar is no longer present. In the scenario I am testing, after increasing the window height once, the vertical scroll bar is not present, but the else condition in the loop is not executed as I was expecting. The while loop continues to execute until maxSteps is 0 and then exits the loop instead of breaking out of the loop when maxSteps is 2. I would appreciate some help with getting the code snippet below to work correctly. I have looked at the FAQs. This line of code "if (null != reg.exists(arrowImage, 0)) "is not getting a null value even when the scroll bar is no longer present in the window.

code snippet:

Screen screen = new Screen();
   Region reg;
   reg = new Region(screen); //Screen is a region
   reg = App.focusedWindow(); // the region of the currently frontmost window
   int maxSteps = 3;
   int steps = 1;
   //increase window height until the vertical scroll bar is no longer present
   while (maxSteps > 0){
                               //check if the up arrow on the vertical scroll bar is present
    if (null != reg.exists(arrowImage, 0)){
        reg.click(increaseWindowHeightImage); //click on increase height image
        reg.wait(0.5);
        maxSteps -= steps;

       }
       else
       {// arrow image not found; so break out of loop
       logger.info("vertical scroll bar not present");
           break;
       }
   }//end while

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Hi,

1.Why wouldn't you just try the straight forward way? :
if reg.exists(arrowImage)

And change your logic accordingly.

2. If you are using the whole screen as a region anyway, you don't need to define it as such. Simple "exists(pattern)" will scan the whole screen anyway.

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

@Eugene: # your 2. : it is Java;-)

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

@Eve: I guess it finds something similar on the screen, when your target has vanished.
So use
new Pattern(arrowImage).exact()
Instead of
arrowImage

Revision history for this message
eve flowers (eveflowers0) said :
#4

Thank you Eugene and Raiman for replying. Using new Pattern(arrowImage).exact() resolved my issue. Appreciate the help, thanks again.