尝试使用AutoIT和Selenium上传文件时找不到文件错误

时间:2017-05-23 15:28:00

标签: selenium-webdriver autoit

当我尝试运行AutoIT.exe脚本或我的Selenium脚本时,它正在抛出'File Not found error'。请指教!

Selenium代码段:===================================

public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver", "C:\\Users\\IBM_ADMIN\\Desktop\\Drivers\\chromedriver.exe");

WebDriver driver = new ChromeDriver(); 
driver.get("http://demo.automationtesting.in/Register.html"); 
driver.manage().window().maximize(); Thread.sleep(2000); 
driver.findElement(By.xpath("//input[@id='imagesrc' and @type='file']")).click(); 
Runtime.getRuntime().exec("C:\\Users\\IBM_ADMIN\\Desktop\\Selenium practise\\SeleniumAssignment\\AutoIT\\MultipleFileUpload.exe"+" "+"C:\\Users\\IBM_ADMIN\\Desktop\\0234_005.pdf"); Thread.sleep(2000); 
driver.findElement(By.xpath("//input[@id='imagesrc' and @type='file']")).click(); 
Runtime.getRuntime().exec("C:\\Users\\IBM_ADMIN\\Desktop\\Selenium practise\\SeleniumAssignment\\AutoIT\\MultipleFileUpload.exe"+" "+"C:\\Users\\IBM_ADMIN\\Desktop\\BRP_SujataChakraborty.pdf"); driver.quit(); } 

AutoIt Code Snippet:============================

ControlFocus("Open","","Edit1") 
ControlSetText("Open","","Edit1",$CmdLine[0]) 
ControlSetText("Open","","Edit1",$CmdLine[1]) 
ControlSetText("Open","","Edit1",$CmdLine[2]) 
ControlClick("Open","","Button1")

1 个答案:

答案 0 :(得分:0)

是浏览器文件对话框活动窗口吗?如果不是自动,则脚本将在窗口中输入值,无论哪个是活动的。确保文件对话框有效吗?一旦启动,就与浏览器进行交互。还有一件事,如果你输入类型是文件,那么你可以使用发送键而不是自动输入值。