使用AutoIt在Selenium WebDriver中通过窗口提示上传文件

我想在Selenium WebDriver中使用AutoIt上传文件。 我有AutoIt代码粘贴在窗口提示文件的path,并单击打开button。

但我的问题是点击“浏览”button使用下面的代码,窗口提示file upload出现,我的代码是不是从这一点移动到我调用自动执行文件的下一行。

driver.findElement(By.xpath("//div[@class='field-group file-inputlist']//div[@class='field-group ']//input")).click(); 

我的AutoIt代码是

 WinWait("[CLASS:#32770]","",10) ; //Set input focus to the edit control of Upload window using the handle returned by WinWait ControlFocus("File Upload","","Edit1") Sleep(2000) ; //Set the File name text on the Edit field ControlSetText("File Upload", "", "Edit1", $CmdLine[1]) Sleep(2000) ; //Click on the Open button ControlClick("File Upload", "","Button1"); 

Eclipse甚至不会抛出任何错误或exception。 代码在浏览器点击浏览button时停止,并打开一个窗口提示符。

注意:如果我closures“手动提示窗口”,则代码将从此处继续。

文件上传的步骤如下:

  1. 点击浏览按钮
  2. 等待窗口打开
  3. 等待窗口处于活动状态(可编辑)
  4. 设置控制,然后选择要上传的文件

尝试步骤2 – 4的示例代码

示例代码:

 WinWait("File Upload") WinActivate("File Upload") ControlSetText("File Upload", "", "[CLASS:Edit;INSTANCE:1]",$CmdLine[1]) ;ControlSetText("Choose", "", "[CLASS:Edit;INSTANCE:1]", "*****Absolute File Path********") ControlClick("File Upload", "", "[CLASS:Button;TEXT:&Open]")