[英]Why won't sikuli script click on the image?
我完全不熟悉sikuli,並嘗試對圖像截圖進行簡單的單擊,這已成為我的火箭科學。
僅供參考-我拍攝了Google徽標的屏幕截圖,並將其保存在我的計算機上。 但是,如果我獲取實際的Google徽標圖片網址,則該腳本有效。
這是使用圖像截圖的正確方法嗎?
public class TestGenericButton {
public static void main(String[] args) throws MalformedURLException {
// Open the main page of Google Code in the default web browser
browse(new URL("http://code.google.com"));
// Create a screen region object that corresponds to the default monitor in full screen
ScreenRegion s = new DesktopScreenRegion();
// Specify an image as the target to find on the screen
//URL imageURL = new URL("http://code.google.com/images/code_logo.gif");
URL imageURL = new URL("img\\google.gif");
Target imageTarget = new ImageTarget(imageURL);
// Wait for the target to become visible on the screen for at most 5 seconds
// Once the target is visible, it returns a screen region object corresponding
// to the region occupied by this target
ScreenRegion r = s.wait(imageTarget,5000);
// Display "Hello World" next to the found target for 3 seconds
Canvas canvas = new DesktopCanvas();
canvas.addLabel(r, "Hello World").display(3);
// Click the center of the found target
Mouse mouse = new DesktopMouse();
mouse.rightClick(r.getCenter());
}
}
不,這不是創建ImageTarget的方法。 您要使用的文件中有圖像,因此您需要傳遞File
而不是URL
。
根據文檔 ,而不是
URL imageURL = new URL("img\\google.gif");
Target imageTarget = new ImageTarget(imageURL);
做
File imageFile = new File("img\\google.gif"); // assumes your working directory is set right...
Target imageTarget = new ImageTarget(imageFile);
提供imageURL,此方法應執行單擊部分:)
private void click(String image) throws FindFailed{
Screen screen = new Screen();
Pattern pattern = new Pattern(image).similar((float) 0.7);
if(screen.find(pattern)!=null){
screen.mouseMove(pattern);
screen.click(pattern);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.