Some time we are getting that image are not displayed on screen which is captured by sikuli at run time.
Such as we open a www.google.com on browser search a text like "testing" and click on searched button we observed that we need to scroll down to click on next button which is at footer. If I used direct sikuli click command to click on next button we will get exception because image not visible on page. I am using below approach to click on next button
I created below function to check image is present on screen or not :
public boolean clipExist(Screen screen, String clip )
{
Match m = screen.exists(clip);
if(m != null)
{
return true;
}
else
{
return false;
}
}
I created below code to scroll down and click on next button if exist:
Screen screen = new Screen()
screen.type(null, "Testing", 0);
screen.click("images/GoogleSearchButton.png", 0);
Thread.sleep(2000);
while( ! clipExist(screen, "images/GoogleLink.png"))
{
screen.wheel(1 , 3);
if(clipExist(screen, "images/Next.png"))
{
screen.click("images/Next.png", 0);
break;
}
}
Such as we open a www.google.com on browser search a text like "testing" and click on searched button we observed that we need to scroll down to click on next button which is at footer. If I used direct sikuli click command to click on next button we will get exception because image not visible on page. I am using below approach to click on next button
I created below function to check image is present on screen or not :
public boolean clipExist(Screen screen, String clip )
{
Match m = screen.exists(clip);
if(m != null)
{
return true;
}
else
{
return false;
}
}
I created below code to scroll down and click on next button if exist:
Screen screen = new Screen()
screen.type(null, "Testing", 0);
screen.click("images/GoogleSearchButton.png", 0);
Thread.sleep(2000);
while( ! clipExist(screen, "images/GoogleLink.png"))
{
screen.wheel(1 , 3);
if(clipExist(screen, "images/Next.png"))
{
screen.click("images/Next.png", 0);
break;
}
}
This comment has been removed by the author.
ReplyDeleteThanks I have drived new piece of code from your above reference which is working fine. My Code first checks for the Image and then scrolls by clicking on down arrow 15 times (you can modify it by modifying value of "h" inside the code) and exists if the image is found.
ReplyDeletepublic boolean scrolldownForImage(String imageName, double time) throws FindFailed {
boolean status = true;
for(int i=0;i < time;i++) {
status = isImagePresent(imageName);
if(!status) {
for(int h=0;h < 15;h++) {
screen.click(IMAGESPATH+"ScrollArrow.png");
}
}else{
break;
}
}
return status;
}
}
public boolean isImagePresent(String image)
{
boolean status = false;
Screen screen = new Screen();
try {
screen.find(IMAGESPATH+image);
status = true;
} catch (FindFailed e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return status;
}
How can we create an object of interface Screen...Screen is an interface not a class...Kindly clarify me if I am wrong...
ReplyDeleteAlso exists method is giving me error..."The method exists(String) is undefined for the type Screen"..
ReplyDeleteAny idea of fixing this error???
Tried your code but the value of variable m is never coming out as null irrespective of the existence of image... any idea...
ReplyDelete