我是sikuli的新手,无法生成Sikuli脚本以用于Web应用程序的上载功能。
Please note that typically, you can automate file upload scenario using Selenium only, no need for Sikuli. For uploading a file you just need to call sendKeys()
method (with file path as argument) on the WebElement that is displayed for file uploading. Code goes like this:
//Put this for textbox near to upload button
driver.findElement(By.id("id_or_other_locator_goes_here")).sendKeys("file_path_goes_here");
And then click the upload button:
driver.findElement(By.xpath("locator_for_upload_button")).click(); // Click Upload button
Sikuli :
I have used Sikuli to automate file download scenario in IE and below are the steps for this:
// Code:
//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")
}
Thanks sandeep!
tried below script using Screen and Pattern class of Sikuli to capture desktop based file from open folder windows at run time and it works!!
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..");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.