0

私は sikuli を初めて使用します。Web アプリケーションのアップロード機能用の Sikuli スクリプトを生成できません。

4

2 に答える 2

0

ありがとうサンディープ!

Sikuli の Screen および Pattern クラスを使用して以下のスクリプトを試し、実行時に開いているフォルダー ウィンドウからデスクトップ ベースのファイルをキャプチャしました。

                     String FileToUpload = "/location of file to upload/"
                     String fileNameLoc = "/fileName_input sikuli image location"
                     String openButtonLoc = "/Open button sikuli image location/"

                     //Code to perform action using action using sikuli script
                     Screen src = new Screen();
                     src.setAutoWaitTimeout(80);
                     Pattern fileName = new Pattern(fileNameLoc).similar((float) 0.5);
                     if (src.exists(fileName, 10) != null)
                     {
                          System.out.println("File Name Pattern exist..");
                          Match match = src.getLastMatch();
                          match.find(fileName);
                          match.click(fileName);
                          match.type(fileName, FileToUpload);
                          match.setAutoWaitTimeout(50);
                     }
                     else
                     {
                          System.out.println("File Name pattern not found on screen..");
                     }

                     Pattern open = new Pattern(openButtonLoc).similar((float) 0.5);
                     if (src.exists(open, 5) != null)
                     {
                          System.out.println("Open Button pattern exist..");
                          Match match = src.getLastMatch();
                          match.find(open);
                          match.click(open);
                          match.setAutoWaitTimeout(30);
                     }
                     else
                     {
                          System.out.println("Open buton pattern not found on screen..");
                     }
于 2016-07-18T06:42:48.020 に答える
0

通常、Selenium のみを使用してファイル アップロード シナリオを自動化でき、Sikuli は不要であることに注意してください。sendKeys()ファイルをアップロードするには、ファイルのアップロード用に表示される WebElement でメソッド (ファイル パスを引数として)を呼び出すだけです。コードは次のようになります。

//Put this for textbox near to upload button
driver.findElement(By.id("id_or_other_locator_goes_here")).sendKeys("file_path_goes_here");

次に、アップロード ボタンをクリックします。

driver.findElement(By.xpath("locator_for_upload_button")).click(); // Click Upload button

シクリ :

Sikuli を使用して、IE でのファイル ダウンロード シナリオを自動化しました。以下はその手順です。

  1. [ファイルのダウンロード] ダイアログ ボックスの [保存] ボタンの最初の画像をキャプチャして保存します
  2. Sikuli jar を Java プロジェクトに入れる
  3. 次のコード スニペットを使用します

// コード:

//Save the file in Downloads directory by using on Sikuli

ScreenRegion s = new DesktopScreenRegion();
Target target = new ImageTarget(new File("SavedImagePath.png"));
ScreenRegion r = s.find(target);
Mouse mouse = new DesktopMouse();   
if (r != null) {
    mouse.click(r.getCenter());
    Thread.sleep(5000);
} else {
    System.out.println("Unable to click using Sikuli")
}
于 2015-07-14T10:36:36.617 に答える