Selenium webdriver 如何在java中使用sikuli和selenium webdriver自动上载多个文件
我是sikuli新手,无法为web应用程序的上载功能生成sikuli脚本。请注意,通常情况下,您可以仅使用Selenium自动执行文件上载场景,而不需要sikuli。 要上载文件,只需在为文件上载显示的WebElement上调用Selenium webdriver 如何在java中使用sikuli和selenium webdriver自动上载多个文件,selenium-webdriver,selenium-chromedriver,sikuli-script,Selenium Webdriver,Selenium Chromedriver,Sikuli Script,我是sikuli新手,无法为web应用程序的上载功能生成sikuli脚本。请注意,通常情况下,您可以仅使用Selenium自动执行文件上载场景,而不需要sikuli。 要上载文件,只需在为文件上载显示的WebElement上调用sendKeys()方法(以文件路径为参数)。代码如下: //Put this for textbox near to upload button driver.findElement(By.id("id_or_other_locator_goes_here")).sen
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在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")
}
谢谢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..");
}
检查此项-类似的开始方式