我是sikuli的新手,无法为Web应用程序生成用于上传功能的Sikuli脚本。
答案 0 :(得分:0)
请注意,通常情况下,您只能使用Selenium自动执行文件上传方案,不需要Sikuli。
要上传文件,您只需要在显示文件上载的WebElement上调用sendKeys()
方法(文件路径为参数)。代码是这样的:
//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:
我已经使用Sikuli在IE中自动执行文件下载方案,以下是步骤:
//代码:
//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")
}
答案 1 :(得分:0)
谢谢sandeep!
使用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..");
}